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. QML Settings doesn't have "remove" function !

QML Settings doesn't have "remove" function !

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
qmlsettingsremovemethods
9 Posts 4 Posters 1.5k Views
  • 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.
  • M Offline
    M Offline
    Mohammadsm
    wrote on 29 Feb 2020, 10:05 last edited by Mohammadsm
    #1

    Hi
    I have some settings in my app, which it's parameters are stored in a file, using Setting API. I can save and load parameters, but need to remove them, sometimes; Like QSettings::remove() in C++.
    But it seems there is no such function in QML API of Settings.

    How it is possible?

    R 1 Reply Last reply 29 Feb 2020, 10:50
    0
    • M Mohammadsm
      29 Feb 2020, 10:05

      Hi
      I have some settings in my app, which it's parameters are stored in a file, using Setting API. I can save and load parameters, but need to remove them, sometimes; Like QSettings::remove() in C++.
      But it seems there is no such function in QML API of Settings.

      How it is possible?

      R Offline
      R Offline
      raven-worx
      Moderators
      wrote on 29 Feb 2020, 10:50 last edited by raven-worx
      #2

      @Mohammadsm
      i havent tried yet, but i guess in QML you only have two values to assign which might unset the value. undefined and null
      worth a try at least
      on the other hand i dont think its possible to remove the whole property from the object itself, after creation

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • M Offline
        M Offline
        Mohammadsm
        wrote on 29 Feb 2020, 17:00 last edited by
        #3

        It's not about property, I mean removing a key from a Settings object:
        https://doc.qt.io/qt-5/qsettings.html#remove
        But doing this in QML.

        Settings in QtQuick, doesn't have remove method :(
        https://doc.qt.io/qt-5/qml-qt-labs-settings-settings.html#methods

        I need to remove a key from Settings object.

        Thank you for responding

        R 1 Reply Last reply 29 Feb 2020, 17:28
        0
        • M Mohammadsm
          29 Feb 2020, 17:00

          It's not about property, I mean removing a key from a Settings object:
          https://doc.qt.io/qt-5/qsettings.html#remove
          But doing this in QML.

          Settings in QtQuick, doesn't have remove method :(
          https://doc.qt.io/qt-5/qml-qt-labs-settings-settings.html#methods

          I need to remove a key from Settings object.

          Thank you for responding

          R Offline
          R Offline
          raven-worx
          Moderators
          wrote on 29 Feb 2020, 17:28 last edited by
          #4

          @Mohammadsm said in QML Settings doesn't have "remove" function !:

          It's not about property, I mean removing a key from a Settings object:

          iitt is, since in the QML Settings type the keys are taken from the properties

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          0
          • M Offline
            M Offline
            Mohammadsm
            wrote on 1 Mar 2020, 04:23 last edited by
            #5

            It didn't worked :(
            I tried:

            setting.setValue("step_1", null)
            

            but the app.conf shows:
            [General]
            step_1=@Variant(\0\0\0\x94)

            and

            setting.setValue("step_1", undefined)
            

            makes:
            [General]
            step_1=@Invalid()

            They don't remove 'step_1' from app.conf file!

            J 1 Reply Last reply 2 Mar 2020, 06:17
            0
            • M Offline
              M Offline
              Munkhtamir
              wrote on 2 Mar 2020, 00:12 last edited by
              #6

              Which variable do you want to remove from your settings?

              Entire Group or child key or file which contains some config?

              M 1 Reply Last reply 2 Mar 2020, 06:43
              0
              • M Mohammadsm
                1 Mar 2020, 04:23

                It didn't worked :(
                I tried:

                setting.setValue("step_1", null)
                

                but the app.conf shows:
                [General]
                step_1=@Variant(\0\0\0\x94)

                and

                setting.setValue("step_1", undefined)
                

                makes:
                [General]
                step_1=@Invalid()

                They don't remove 'step_1' from app.conf file!

                J Offline
                J Offline
                J.Hilk
                Moderators
                wrote on 2 Mar 2020, 06:17 last edited by
                #7

                @Mohammadsm
                QSettings is technically still part of the labs import and not really considered production ready (may change become incompatible at any moment)

                So, this seems like a perfect opportunity to make a feature request at https://bugreports.qt.io/secure/Dashboard.jspa

                meanwhile,
                I suggest subclassing QSettings, and making the remove function Q_INVOKABLE and exposing that new class for your use in QML


                Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                Q: What's that?
                A: It's blue light.
                Q: What does it do?
                A: It turns blue.

                M 1 Reply Last reply 2 Mar 2020, 06:50
                0
                • M Munkhtamir
                  2 Mar 2020, 00:12

                  Which variable do you want to remove from your settings?

                  Entire Group or child key or file which contains some config?

                  M Offline
                  M Offline
                  Mohammadsm
                  wrote on 2 Mar 2020, 06:43 last edited by
                  #8

                  @Munkhtamir
                  I want to remove "step_1" which is a key in my Settings object:

                  Settings{
                      id: stg
                  }
                  .
                  .
                  .
                  stg.setValue("step_1", 127)
                  
                  1 Reply Last reply
                  0
                  • J J.Hilk
                    2 Mar 2020, 06:17

                    @Mohammadsm
                    QSettings is technically still part of the labs import and not really considered production ready (may change become incompatible at any moment)

                    So, this seems like a perfect opportunity to make a feature request at https://bugreports.qt.io/secure/Dashboard.jspa

                    meanwhile,
                    I suggest subclassing QSettings, and making the remove function Q_INVOKABLE and exposing that new class for your use in QML

                    M Offline
                    M Offline
                    Mohammadsm
                    wrote on 2 Mar 2020, 06:50 last edited by
                    #9

                    @J-Hilk
                    I managed the required behavior, somehow.

                    By blanking the key value:

                    stg.setValue("step_1", "")
                    

                    then scanning the keys, which have non-empty value, and skipping the empty ones.

                    I'll file a bug, cause I think it's a needed method!
                    By the way, thank you all

                    1 Reply Last reply
                    0

                    9/9

                    2 Mar 2020, 06:50

                    • Login

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