Solved QtQuick.labs.settings
-
Hi all. I am trying to save dictionary (js object) in settings.
Settings { id: settings property var mru :({}) } function foo() { console.log(settings.mru["h"]) settings.mru["h"] = 3 }
But, depending of if i initialize mru in settings, i receive an error either it saves invalid object or it saves something, that looks right, but it does not want to load value from settings.
What should i do? Or maybe create own class derived from QSettings? But i would bad solution -
... but it does not want to load value from settings.
Are you sure you have posted the correct code here? Because as I can see you are printing the value first and then adding the value later. So obviously the value will be undefined.
-
Sorry, it was quickwritten example, with a mistake.
I found a solution, but face another problem:Settings { id: settings property var mru Component.onCompleted: { if (typeof mru === 'undefined') mru = {} } function foo() { if ('e' in settings.mru) console.log(settings.mru['e']) settings.mru['e'] = 4 }
The example above saves settings.
But when I try to modify the existing value (for example, change 4 to 6) it would not be saved, no matter how many times i rerun the program. It modifies local object mru, but no changes applied in settings file.All the problems were solved! To save settings, you should use in the end something like this:
settings.mru = settings.mru
It seems, that saving is only executed when the operator = is used.
-
@denix56 Is this case similar to https://bugreports.qt.io/browse/QTBUG-45316 ?
-
@p3c0 yeah, you are right