<?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 object not overwriting the existing group&#x27;s key value, creates [General] and stores data, how to make it write on the actual location in the .ini file?]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<ol>
<li>I have global <code>QSetting *iniSetting =new QSetting(filename,QSettings::IniFormat,this);</code>, reads the <code>.ini</code> file and creates groups.<br />
2)I have global <code>QTreeWidget</code>object, it is getting populated by <code>QTreeWidgetItems </code> objects , data from the <code>iniSettings</code> object.<br />
3)Now while user double-clicks a group value on <code>QTreeWidget</code> object and edits the column 2 value ,<code>QTreeWidget</code>generates the signal <code>itemChanged(QTreeWidgetItem*,int); </code> this I have connected to the slot <code>itemChanged(QTreeWidgetItem *item,int col);</code>of the Mainwindow object. Now I want to get the edited value and update the value in the <code>.ini</code> file but it is not happening properly, please help me.</li>
</ol>
<p dir="auto">code:</p>
<pre><code>
 void Widget::itemChanged(QTreeWidgetItem *item,int col)
 {
    iniSettings-&gt;setValue(item-&gt;text(0),item-&gt;text(col));//here item-&gt;text(0) is key of a group in iniSettings object and item-&gt;text(col) new value edit by user corresponds to key and it has to be updated on the .ini file, but not working properly.
// this will create contents in .ini file like this:
[General]
key1=value
//output not overwritting the existing group using key with new value but creates the above contents in .ini file how to make this to update on the correct group ?
</code></pre>
]]></description><link>https://forum.qt.io/topic/95286/qsettings-object-not-overwriting-the-existing-group-s-key-value-creates-general-and-stores-data-how-to-make-it-write-on-the-actual-location-in-the-ini-file</link><generator>RSS for Node</generator><lastBuildDate>Tue, 21 Apr 2026 12:19:19 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/95286.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 05 Oct 2018 06:22:45 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to QSettings object not overwriting the existing group&#x27;s key value, creates [General] and stores data, how to make it write on the actual location in the .ini file? on Fri, 05 Oct 2018 10:44:41 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/raven-worx">@<bdi>raven-worx</bdi></a> it is working perfectly, Awesome.<br />
Thanks a lot.</p>
]]></description><link>https://forum.qt.io/post/485387</link><guid isPermaLink="true">https://forum.qt.io/post/485387</guid><dc:creator><![CDATA[thippu]]></dc:creator><pubDate>Fri, 05 Oct 2018 10:44:41 GMT</pubDate></item><item><title><![CDATA[Reply to QSettings object not overwriting the existing group&#x27;s key value, creates [General] and stores data, how to make it write on the actual location in the .ini file? on Fri, 05 Oct 2018 09:45:44 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/thippu">@<bdi>thippu</bdi></a><br />
assuming your tree widget only has 1 sub-level a simple check can be:</p>
<pre><code>QTreeWidgetItem* item = ...;
if( QTreeWidgetItem* parent = item-&gt;parent() )
{
     // item is a child (= key)
     QString keyPath = QString("%1/%2").arg(parent-&gt;text(0)).arg(item-&gt;text(0));
     QVariant val = iniSettings-&gt;value( keyPath ); // reading
     iniSettings-&gt;setValue( keyPath, val ); // writing
}
else
{
     // item is a root item (= group)
}
</code></pre>
]]></description><link>https://forum.qt.io/post/485382</link><guid isPermaLink="true">https://forum.qt.io/post/485382</guid><dc:creator><![CDATA[raven-worx]]></dc:creator><pubDate>Fri, 05 Oct 2018 09:45:44 GMT</pubDate></item><item><title><![CDATA[Reply to QSettings object not overwriting the existing group&#x27;s key value, creates [General] and stores data, how to make it write on the actual location in the .ini file? on Fri, 05 Oct 2018 09:39:42 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jsulm">@<bdi>jsulm</bdi></a> I'm stuck here if I find the group name I can complete this, don't know how to fix it help me.</p>
]]></description><link>https://forum.qt.io/post/485380</link><guid isPermaLink="true">https://forum.qt.io/post/485380</guid><dc:creator><![CDATA[thippu]]></dc:creator><pubDate>Fri, 05 Oct 2018 09:39:42 GMT</pubDate></item><item><title><![CDATA[Reply to QSettings object not overwriting the existing group&#x27;s key value, creates [General] and stores data, how to make it write on the actual location in the .ini file? on Fri, 05 Oct 2018 08:36:41 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/thippu">@<bdi>thippu</bdi></a> Again: a root node does NOT have a parent.</p>
]]></description><link>https://forum.qt.io/post/485364</link><guid isPermaLink="true">https://forum.qt.io/post/485364</guid><dc:creator><![CDATA[jsulm]]></dc:creator><pubDate>Fri, 05 Oct 2018 08:36:41 GMT</pubDate></item><item><title><![CDATA[Reply to QSettings object not overwriting the existing group&#x27;s key value, creates [General] and stores data, how to make it write on the actual location in the .ini file? on Fri, 05 Oct 2018 08:11:54 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/raven-worx">@<bdi>raven-worx</bdi></a><br />
like below I'm doing to create nodes and children.</p>
<pre><code> QTreeWidgetItem&amp; Widget::createRoot(const QString &amp;groupname)
{
   QTreeWidgetItem *root=new QTreeWidgetItem(displayTreeWidget);//here parameter is QTreeWidget
   root-&gt;setText(0,groupname);
  displayTreeWidget-&gt;addTopLevelItem(root);
return *root;
}

//method to create children and attach them to toplevelitem
void Widget::createChild(QTreeWidgetItem &amp;rootaddress,const QString &amp;key,const QVariant &amp;value)
{
  QTreeWidgetItem *child=new QTreeWidgetItem;
 child-&gt;setText(0,key);
child-&gt;setTextAlignment(0,Qt::AlignCenter);
child-&gt;setData(1,2,value);
rootaddress.addChild(child);
}
//these two methods are called while initial group creation
//mentioned with bold text in the code below
</code></pre>
<blockquote>
<p dir="auto">Groups have been created initially using code:</p>
<pre><code class="language-foreach(">{
        iniSettings-&gt;beginGroup(group);
        QTreeWidgetItem &amp;rootaddress=**createRoot(group);** //it creates group text as node on QTreeWidget object.
         foreach( QString key, iniSettings-&gt;childKeys() )
         {
                QVariant val = iniSettings-&gt;value(key);
                ***createChild(rootaddress,key,val); *** /adds key and value of the group as the child nodes to the QTreeWidget using 
                rootaddress.
         }
     iniSettings-&gt;endGroup();
} 
</code></pre>
<p dir="auto">Now if a user changes(or edits) any value on the <code>QTreeWidgetItem </code> on <code>QTreeWidget</code> object, I want update this values to existing group key/value in the <code>QSetting</code> and  the <code>.ini</code> file ,</p>
</blockquote>
]]></description><link>https://forum.qt.io/post/485362</link><guid isPermaLink="true">https://forum.qt.io/post/485362</guid><dc:creator><![CDATA[thippu]]></dc:creator><pubDate>Fri, 05 Oct 2018 08:11:54 GMT</pubDate></item><item><title><![CDATA[Reply to QSettings object not overwriting the existing group&#x27;s key value, creates [General] and stores data, how to make it write on the actual location in the .ini file? on Fri, 05 Oct 2018 07:56:11 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/thippu">@<bdi>thippu</bdi></a><br />
probably because parent is a NULL pointer when you call this piece of code for all your items.<br />
Your root items of course do not have a parent item.</p>
]]></description><link>https://forum.qt.io/post/485358</link><guid isPermaLink="true">https://forum.qt.io/post/485358</guid><dc:creator><![CDATA[raven-worx]]></dc:creator><pubDate>Fri, 05 Oct 2018 07:56:11 GMT</pubDate></item><item><title><![CDATA[Reply to QSettings object not overwriting the existing group&#x27;s key value, creates [General] and stores data, how to make it write on the actual location in the .ini file? on Fri, 05 Oct 2018 07:54:08 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/raven-worx">@<bdi>raven-worx</bdi></a><br />
I did</p>
<pre><code> void Widget::itemChanged(QTreeWidgetItem *item,int col)
{
QTreeWidgetItem *parent=item-&gt;parent();
qDebug()&lt;&lt;parent-&gt;text(0);//App is getting crashed here, do not know why? how to get text from this root?</code></pre>
]]></description><link>https://forum.qt.io/post/485357</link><guid isPermaLink="true">https://forum.qt.io/post/485357</guid><dc:creator><![CDATA[thippu]]></dc:creator><pubDate>Fri, 05 Oct 2018 07:54:08 GMT</pubDate></item><item><title><![CDATA[Reply to QSettings object not overwriting the existing group&#x27;s key value, creates [General] and stores data, how to make it write on the actual location in the .ini file? on Fri, 05 Oct 2018 07:49:36 GMT]]></title><description><![CDATA[<p dir="auto">okay, but my group name is dynamic.</p>
<blockquote>
<ol>
<li></li>
</ol>
<pre><code>iniSettings-&gt;beginGroup("mygroup");
QVariant val = iniSettings-&gt;value("mykey");
iniSettings-&gt;endGroup();
</code></pre>
<ol start="2">
<li></li>
</ol>
<pre><code>QVariant val = iniSettings-&gt;value("mygroup/mykey");
</code></pre>
</blockquote>
]]></description><link>https://forum.qt.io/post/485356</link><guid isPermaLink="true">https://forum.qt.io/post/485356</guid><dc:creator><![CDATA[thippu]]></dc:creator><pubDate>Fri, 05 Oct 2018 07:49:36 GMT</pubDate></item><item><title><![CDATA[Reply to QSettings object not overwriting the existing group&#x27;s key value, creates [General] and stores data, how to make it write on the actual location in the .ini file? on Fri, 05 Oct 2018 07:44:01 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/thippu">@<bdi>thippu</bdi></a> said in <a href="/post/485351">QSettings object not overwriting the existing group's key value, creates [General] and stores data, how to make it write on the actual location in the .ini file?</a>:</p>
<blockquote>
<p dir="auto">how to get parent node text using current QTreeWidgetItem?</p>
</blockquote>
<p dir="auto"><a href="http://doc.qt.io/qt-5/qtreewidgetitem.html#parent" target="_blank" rel="noopener noreferrer nofollow ugc">QTreeWidgetItem::parent()</a></p>
]]></description><link>https://forum.qt.io/post/485352</link><guid isPermaLink="true">https://forum.qt.io/post/485352</guid><dc:creator><![CDATA[raven-worx]]></dc:creator><pubDate>Fri, 05 Oct 2018 07:44:01 GMT</pubDate></item><item><title><![CDATA[Reply to QSettings object not overwriting the existing group&#x27;s key value, creates [General] and stores data, how to make it write on the actual location in the .ini file? on Fri, 05 Oct 2018 07:41:56 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/raven-worx">@<bdi>raven-worx</bdi></a> , I think I got it.<br />
my current key/value stored in <code>QTreeWidgetItem</code> and this is attached root node, root node contains the group name.<br />
how to get parent node text using current <code>QTreeWidgetItem</code>?</p>
]]></description><link>https://forum.qt.io/post/485351</link><guid isPermaLink="true">https://forum.qt.io/post/485351</guid><dc:creator><![CDATA[thippu]]></dc:creator><pubDate>Fri, 05 Oct 2018 07:41:56 GMT</pubDate></item><item><title><![CDATA[Reply to QSettings object not overwriting the existing group&#x27;s key value, creates [General] and stores data, how to make it write on the actual location in the .ini file? on Fri, 05 Oct 2018 07:42:25 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/thippu">@<bdi>thippu</bdi></a> said in <a href="/post/485342">QSettings object not overwriting the existing group's key value, creates [General] and stores data, how to make it write on the actual location in the .ini file?</a>:</p>
<blockquote>
<p dir="auto">So why to call again QSettings::beginGroup.</p>
</blockquote>
<p dir="auto">because this sets the group to read/write from (if you do not specify the group in the key path already).</p>
<p dir="auto">There are the 2 following ways to read the key <code>mykey</code> from the group <code>mygroup</code></p>
<ol>
<li></li>
</ol>
<pre><code>iniSettings-&gt;beginGroup("mygroup");
QVariant val = iniSettings-&gt;value("mykey");
iniSettings-&gt;endGroup();
</code></pre>
<ol start="2">
<li></li>
</ol>
<pre><code>QVariant val = iniSettings-&gt;value("mygroup/mykey");
</code></pre>
]]></description><link>https://forum.qt.io/post/485349</link><guid isPermaLink="true">https://forum.qt.io/post/485349</guid><dc:creator><![CDATA[raven-worx]]></dc:creator><pubDate>Fri, 05 Oct 2018 07:42:25 GMT</pubDate></item><item><title><![CDATA[Reply to QSettings object not overwriting the existing group&#x27;s key value, creates [General] and stores data, how to make it write on the actual location in the .ini file? on Fri, 05 Oct 2018 07:22:10 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/raven-worx">@<bdi>raven-worx</bdi></a> , I did not get this</p>
<blockquote>
<p dir="auto">to write a value into a group you need either set the key of the value to <code>group/key</code></p>
</blockquote>
]]></description><link>https://forum.qt.io/post/485343</link><guid isPermaLink="true">https://forum.qt.io/post/485343</guid><dc:creator><![CDATA[thippu]]></dc:creator><pubDate>Fri, 05 Oct 2018 07:22:10 GMT</pubDate></item><item><title><![CDATA[Reply to QSettings object not overwriting the existing group&#x27;s key value, creates [General] and stores data, how to make it write on the actual location in the .ini file? on Fri, 05 Oct 2018 07:18:43 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/raven-worx">@<bdi>raven-worx</bdi></a> <code>iniSettings</code> has been populated by group names using <code>.ini</code> file already, So why to call again QSettings::beginGroup.<br />
Or maybe I did not get what you are saying.</p>
]]></description><link>https://forum.qt.io/post/485342</link><guid isPermaLink="true">https://forum.qt.io/post/485342</guid><dc:creator><![CDATA[thippu]]></dc:creator><pubDate>Fri, 05 Oct 2018 07:18:43 GMT</pubDate></item><item><title><![CDATA[Reply to QSettings object not overwriting the existing group&#x27;s key value, creates [General] and stores data, how to make it write on the actual location in the .ini file? on Fri, 05 Oct 2018 07:11:03 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/thippu">@<bdi>thippu</bdi></a> said in <a href="/post/485339">QSettings object not overwriting the existing group's key value, creates [General] and stores data, how to make it write on the actual location in the .ini file?</a>:</p>
<blockquote>
<p dir="auto">Now if a user changes(or edits) any value on the QTreeWidgetItem on QTreeWidget object, I want update this values to existing group key/value in the QSetting and  the .ini file</p>
</blockquote>
<p dir="auto">yes, and why is my advise wrong here?!</p>
]]></description><link>https://forum.qt.io/post/485340</link><guid isPermaLink="true">https://forum.qt.io/post/485340</guid><dc:creator><![CDATA[raven-worx]]></dc:creator><pubDate>Fri, 05 Oct 2018 07:11:03 GMT</pubDate></item><item><title><![CDATA[Reply to QSettings object not overwriting the existing group&#x27;s key value, creates [General] and stores data, how to make it write on the actual location in the .ini file? on Fri, 05 Oct 2018 07:08:37 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/raven-worx">@<bdi>raven-worx</bdi></a><br />
you are not got what my problem is,<br />
Groups have been created initially using code:</p>
<pre><code class="language-foreach(">{
        iniSettings-&gt;beginGroup(group);
        QTreeWidgetItem &amp;rootaddress=createRoot(group); //it creates group text as node on QTreeWidget object.
         foreach( QString key, iniSettings-&gt;childKeys() )
         {
                QVariant val = iniSettings-&gt;value(key);
                createChild(rootaddress,key,val); //adds key and value of the group as the child nodes to the QTreeWidget using 
                rootaddress.
         }
     iniSettings-&gt;endGroup();
} 
</code></pre>
<p dir="auto">Now if a user changes(or edits) any value on the <code>QTreeWidgetItem </code> on <code>QTreeWidget</code> object, I want update this values to existing group key/value in the <code>QSetting</code> and  the <code>.ini</code> file ,</p>
]]></description><link>https://forum.qt.io/post/485339</link><guid isPermaLink="true">https://forum.qt.io/post/485339</guid><dc:creator><![CDATA[thippu]]></dc:creator><pubDate>Fri, 05 Oct 2018 07:08:37 GMT</pubDate></item><item><title><![CDATA[Reply to QSettings object not overwriting the existing group&#x27;s key value, creates [General] and stores data, how to make it write on the actual location in the .ini file? on Fri, 05 Oct 2018 06:36:43 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/thippu">@<bdi>thippu</bdi></a><br />
to write a value into a group you need either set the key of the value to <code>group/key</code><br />
or you call <code>QSettings::beginGroup()</code> / <code>QSettings::endGroup()</code> before calling <code>QSettings::setValue()</code></p>
]]></description><link>https://forum.qt.io/post/485334</link><guid isPermaLink="true">https://forum.qt.io/post/485334</guid><dc:creator><![CDATA[raven-worx]]></dc:creator><pubDate>Fri, 05 Oct 2018 06:36:43 GMT</pubDate></item></channel></rss>