We have moved to a new Sailfish OS Forum. Please start new discussions there.
1

Nemo.Configuration: store array of objects

asked 2019-12-17 13:10:22 +0200

this post is marked as community wiki

This post is a wiki. Anyone with karma >75 is welcome to improve it.

updated 2019-12-17 13:10:22 +0200

Tanghus gravatar image
  1. Is it possible?
  2. If so, how? sync() doesn't seem to have any effect.
  3. Or will I have to (de)serialize it manually?
edit retag flag offensive close delete

Comments

It was already possible, but is not anymore. I stored an array of objects with a ConfigurationValue. It never worked as a property of a ConfigurationGroup

ConfigurationValue {
            key: "/apps/harbour-zutun/settings/filters/projects"
            defaultValue: []
}

...but since some time this also doesn't work anymore.

michfu ( 2019-12-17 18:23:24 +0200 )edit

OK, thanks. So maybe this should be changed to a bug report. I have no idea where to submit an actual report though.

Tanghus ( 2019-12-17 19:37:36 +0200 )edit

2 Answers

Sort by » oldest newest most voted
3

answered 2019-12-18 11:52:33 +0200

michfu gravatar image

updated 2019-12-18 11:59:50 +0200

I did some more research. It seems like I got an error in my app.

This minimal example works:

        ConfigurationValue {
            id: array
            key: "/apps/test/array"
            defaultValue: []
        }
        Label { text: "entries: " + array.value.join() }
        Label { text: "length: " + array.value.length }
        Button {
            text: "push1"
            onClicked:{
                var a = array.value
                a.push("e" + a.length)
                array.value = a
                console.log(typeof array.value, array.value)
            }
        }
        Button {
            text: "reset"
            onClicked: array.value = array.defaultValue
        }

This one doesnt:

        ConfigurationGroup {
            id: cg
            path: "/apps/test/group"
            property var array: []
        }
        Label { text: "entries: " + cg.array.join() }
        Label { text: "length: " + cg.array.length }
        Button {
            text: "push"
            onClicked:{
                var a = cg.array
                a.push("e" + a.length)
                cg.array = a
                console.log(typeof cg.array, cg.array)
            }
        }
        Button {
            text: "reset"
            onClicked: cg.array = []
        }

PS: Also it seems I posted this already in the list :) https://lists.sailfishos.org/pipermail/devel/2017-November/008088.html

edit flag offensive delete publish link more

Comments

This is great. Just what I need. Thank you! I haven't tested it yet, so I'll wait with accepting the answer, just for formalities :)

PS: Also it seems I posted this already in the list :)

I was sure I had read something about it, but could find it.

Tanghus ( 2019-12-18 12:06:52 +0200 )edit
1

Just for info: Actually I'm using the ConfigurationValue nested inside a group like this:

        ConfigurationGroup {
            id: settings
            path: "/apps/testapp"
            property int someInt: 42
            property ConfigurationValue array: ConfigurationValue {
                key: settings.path + "/array"
                defaultValue: []
            }
        }
        Label { text: "entries: " + settings.array.value.join() }
        Label { text: "length: " + settings.array.value.length }
        Button {
            text: "push"
            onClicked:{
                var a = settings.array.value
                a.push("e" + a.length)
                settings.array.value = a
                console.log(typeof settings.array.value, settings.array.value)
            }
        }
michfu ( 2019-12-18 15:16:25 +0200 )edit

Thanks @michfu 👍

Tanghus ( 2019-12-19 11:43:01 +0200 )edit
0

answered 2019-12-19 11:55:33 +0200

this post is marked as community wiki

This post is a wiki. Anyone with karma >75 is welcome to improve it.

updated 2019-12-19 11:55:33 +0200

Tanghus gravatar image

After I made my first app for SFOS, someone asked me why I had both a wrapper around QSettings (Nemo.Configuration wasn't allowed in Harbour AFAIRC?), and a wrapper around LocalStorage.

At that time it was just to feel this new platform on it's teeth to see what could be used; now my answer is, that it's just not worth the effort to manipulate lists, especially lists of objects, that way. That's what a database is for, and doing it that way would be trying to reinvent the wheel, just more error prone and difficult to maintain.

I already use a simple database layer, that I use in my other apps, and I will just make a couple of methods and it's done and tested.

I have marked @michfu's answer as accepted, because it's the correct answer to my question, and solves the issue of storing simple arrays.

edit flag offensive delete publish link more
Login/Signup to Answer

Question tools

Follow
3 followers

Stats

Asked: 2019-12-17 13:10:22 +0200

Seen: 245 times

Last updated: Dec 19 '19