<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[[QSettings] how to update an array?]]></title><description><![CDATA[<p dir="auto">Hello,<br />
I created settings which contain an array of models, each model having some properties, for example, property1 property2...<br />
At some point, I want to modify properties of one of the entries in models.<br />
I found that I can find the index of the entry, and with</p>
<pre><code>beginWriteArray("Models")
</code></pre>
<p dir="auto">like here:</p>
<pre><code>            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()
</code></pre>
<p dir="auto">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.<br />
Do I something wrong (yes, of course)?<br />
Is there another method, except read all, delete all and write it again?</p>
]]></description><link>https://forum.qt.io/topic/139542/qsettings-how-to-update-an-array</link><generator>RSS for Node</generator><lastBuildDate>Fri, 06 Nov 2026 15:11:39 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/139542.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 24 Sep 2022 15:36:41 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to [QSettings] how to update an array? on Sun, 25 Sep 2022 18:24:44 GMT]]></title><description><![CDATA[<p dir="auto">So you have it working now ?</p>
]]></description><link>https://forum.qt.io/post/730118</link><guid isPermaLink="true">https://forum.qt.io/post/730118</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Sun, 25 Sep 2022 18:24:44 GMT</pubDate></item><item><title><![CDATA[Reply to [QSettings] how to update an array? on Sun, 25 Sep 2022 12:35:20 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sgaist">@<bdi>SGaist</bdi></a> Thanks for your suggestion.<br />
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 <code>beginWriteArray</code>:<br />
<a href="https://bugreports.qt.io/browse/QTBUG-23944" target="_blank" rel="noopener noreferrer nofollow ugc">https://bugreports.qt.io/browse/QTBUG-23944</a><br />
Thus, the valid code is:</p>
<pre><code>                        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()
         

</code></pre>
]]></description><link>https://forum.qt.io/post/730102</link><guid isPermaLink="true">https://forum.qt.io/post/730102</guid><dc:creator><![CDATA[YvesB]]></dc:creator><pubDate>Sun, 25 Sep 2022 12:35:20 GMT</pubDate></item><item><title><![CDATA[Reply to [QSettings] how to update an array? on Sat, 24 Sep 2022 19:59:25 GMT]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">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 ?</p>
]]></description><link>https://forum.qt.io/post/730061</link><guid isPermaLink="true">https://forum.qt.io/post/730061</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Sat, 24 Sep 2022 19:59:25 GMT</pubDate></item></channel></rss>