Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QSettings how to remove elements from array?

QSettings how to remove elements from array?

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 2 Posters 3.3k 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.
  • H Offline
    H Offline
    hezf
    wrote on 9 Apr 2016, 02:29 last edited by
    #1

    I have a array save in QSettings
    I can modify the element
    But I don't know how to remove it
    Anybody know?

    1 Reply Last reply
    0
    • R Offline
      R Offline
      Ratzz
      wrote on 9 Apr 2016, 06:24 last edited by
      #2

      Hi ,
      Did you try remove ? http://doc.qt.io/qt-4.8/qsettings.html#remove

      --Alles ist gut.

      H 1 Reply Last reply 9 Apr 2016, 07:11
      0
      • R Ratzz
        9 Apr 2016, 06:24

        Hi ,
        Did you try remove ? http://doc.qt.io/qt-4.8/qsettings.html#remove

        H Offline
        H Offline
        hezf
        wrote on 9 Apr 2016, 07:11 last edited by
        #3

        @Ratzz Yes,I could remove the element's key
        But the array's element is still ,just an empty one

        1 Reply Last reply
        0
        • R Offline
          R Offline
          Ratzz
          wrote on 9 Apr 2016, 07:24 last edited by Ratzz 4 Sept 2016, 07:25
          #4

          I did you get you clearly.. can you show the code or explain me more?

          --Alles ist gut.

          H 1 Reply Last reply 9 Apr 2016, 07:33
          0
          • R Ratzz
            9 Apr 2016, 07:24

            I did you get you clearly.. can you show the code or explain me more?

            H Offline
            H Offline
            hezf
            wrote on 9 Apr 2016, 07:33 last edited by
            #5

            @Ratzz okay

            //this is I write a array
                QSettings setting("TEST","demo1");
                setting.beginWriteArray("array1");
                for(auto i=0;i<10;i++){
                    setting.setArrayIndex(i);
                    setting.setValue("demo","value"+QString::number(i));
                }
                setting.endArray();
            
            //this is I read a array
                auto size = setting.beginReadArray("array1");
                for(auto i=0;i<size;i++){
                    setting.setArrayIndex(i);
                    qDebug()<<setting.value("demo");
                }
                setting.endArray();
            
            //read the array and remove
                setting.beginReadArray("array1");
                setting.setArrayIndex(5);
                setting.remove("demo");
                setting.endArray();
            //the result is 
            //QVariant(QString, "value0")
            //QVariant(QString, "value1")
            //QVariant(QString, "value2")
            //QVariant(QString, "value3")
            //QVariant(QString, "value4")
            //QVariant(Invalid)
            //QVariant(QString, "value6")
            //QVariant(QString, "value7")
            //QVariant(QString, "value8")
            //QVariant(QString, "value9")
            
            //write the array and remove
                setting.beginWriteArray("array1");
                setting.setArrayIndex(5);
                setting.remove("demo");
                setting.endArray();
            
            //result
            QVariant(QString, "value0")
            QVariant(QString, "value1")
            QVariant(QString, "value2")
            QVariant(QString, "value3")
            QVariant(QString, "value4")
            QVariant(Invalid)
            

            Is it clearly?

            1 Reply Last reply
            0
            • R Offline
              R Offline
              Ratzz
              wrote on 9 Apr 2016, 07:54 last edited by Ratzz 4 Sept 2016, 07:55
              #6

              I think you need to set back the value to QSettings after you remove.

              --Alles ist gut.

              H 1 Reply Last reply 9 Apr 2016, 08:49
              0
              • R Ratzz
                9 Apr 2016, 07:54

                I think you need to set back the value to QSettings after you remove.

                H Offline
                H Offline
                hezf
                wrote on 9 Apr 2016, 08:49 last edited by
                #7

                @Ratzz
                But when I want remove the last one ,what can I do?

                I get a stupid method,read all keys and value to a list
                and then clear the settings
                removeat(index) the list
                At last ,write this list to settings.

                1 Reply Last reply
                0

                1/7

                9 Apr 2016, 02:29

                • Login

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