Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. [QSettings] how to update an array?
Qt 6.12 LTS is out! See what's new in the release blog

[QSettings] how to update an array?

Scheduled Pinned Locked Moved Unsolved Qt for Python
4 Posts 2 Posters 1.0k 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.
  • Y Offline
    Y Offline
    YvesB
    wrote on last edited by
    #1

    Hello,
    I created settings which contain an array of models, each model having some properties, for example, property1 property2...
    At some point, I want to modify properties of one of the entries in models.
    I found that I can find the index of the entry, and with

    beginWriteArray("Models")
    

    like here:

                index: int = 2
                n: int = self.settings.beginWriteArray("Models")
                self.settings.setArrayIndex(index)
                self.settings.setValue("language", language)
                self.settings.setValue("name", name)
                self.settings.endArray()
    

    this works except that after that, the size of the array is set such that my entry is then the last one. The following entries are still present, but ignored because of the size. I have for example three entries 1, 2, 3, but the size is 2 if I edited the 2 one.
    Do I something wrong (yes, of course)?
    Is there another method, except read all, delete all and write it again?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      I am currently unsure about the behaviour of the begin/end write array methods. In between, what happens if you move the index through all the entries and change just the one in the middle ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      Y 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        I am currently unsure about the behaviour of the begin/end write array methods. In between, what happens if you move the index through all the entries and change just the one in the middle ?

        Y Offline
        Y Offline
        YvesB
        wrote on last edited by YvesB
        #3

        @SGaist Thanks for your suggestion.
        In the mean time, I had a look inthe tracker and found that I missed to specify the number of records in the call to beginWriteArray:
        https://bugreports.qt.io/browse/QTBUG-23944
        Thus, the valid code is:

                                index: int = 2
                                n: int = self.settings.beginReadArray("Models")
                                self.settings.endArray()
                                self.settings.beginWriteArray("Models", n)
                                self.settings.setArrayIndex(index)
                                self.settings.setValue("language", language)
                                self.settings.setValue("name", name)
                                self.settings.endArray()
                 
        
        
        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          So you have it working now ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          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
          • Unsolved