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 !
QtWS25 Last Chance

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.
  • MohammadsmM Offline
    MohammadsmM Offline
    Mohammadsm
    wrote on 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?

    raven-worxR 1 Reply Last reply
    0
    • MohammadsmM Mohammadsm

      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?

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on 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
      • MohammadsmM Offline
        MohammadsmM Offline
        Mohammadsm
        wrote on 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

        raven-worxR 1 Reply Last reply
        0
        • MohammadsmM Mohammadsm

          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

          raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on 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
          • MohammadsmM Offline
            MohammadsmM Offline
            Mohammadsm
            wrote on 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.HilkJ 1 Reply Last reply
            0
            • M Offline
              M Offline
              Munkhtamir
              wrote on 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?

              MohammadsmM 1 Reply Last reply
              0
              • MohammadsmM Mohammadsm

                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.HilkJ Offline
                J.HilkJ Offline
                J.Hilk
                Moderators
                wrote on 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.

                MohammadsmM 1 Reply Last reply
                0
                • M Munkhtamir

                  Which variable do you want to remove from your settings?

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

                  MohammadsmM Offline
                  MohammadsmM Offline
                  Mohammadsm
                  wrote on 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.HilkJ J.Hilk

                    @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

                    MohammadsmM Offline
                    MohammadsmM Offline
                    Mohammadsm
                    wrote on 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

                    • Login

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