Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. QtQuick.labs.settings

QtQuick.labs.settings

Scheduled Pinned Locked Moved Solved QML and Qt Quick
5 Posts 2 Posters 1.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • denix56D Offline
    denix56D Offline
    denix56
    wrote on last edited by denix56
    #1

    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

    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      @denix56

      ... 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.

      157

      1 Reply Last reply
      0
      • denix56D Offline
        denix56D Offline
        denix56
        wrote on last edited by denix56
        #3

        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.

        1 Reply Last reply
        0
        • p3c0P Offline
          p3c0P Offline
          p3c0
          Moderators
          wrote on last edited by
          #4

          @denix56 Is this case similar to https://bugreports.qt.io/browse/QTBUG-45316 ?

          157

          denix56D 1 Reply Last reply
          0
          • p3c0P p3c0

            @denix56 Is this case similar to https://bugreports.qt.io/browse/QTBUG-45316 ?

            denix56D Offline
            denix56D Offline
            denix56
            wrote on last edited by
            #5

            @p3c0 yeah, you are right

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved