<?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[How to save settings of a window that contains widgets with same object name?]]></title><description><![CDATA[<p dir="auto">I have a QMainWindow where I create new instances of a specific <code>.ui</code> created on Qt Designer, each new instance the widgets contains the same object name, example:</p>
<pre><code>// test.h
#pragma once
#include "stdafx.h"

QT_BEGIN_NAMESPACE
namespace Ui { class Form; };
QT_END_NAMESPACE

class Test : public QWidget 
{
    Q_OBJECT
public:
    Ui::Form* ui;
    Test(QWidget* parent = nullptr) : QWidget(parent), ui(new Ui::Form()) {
        ui-&gt;setupUi(this);
    }
};


// mainwindow
Test test = new Test(...);   // &lt;-
Test test_2 = new Test(...); // &lt;- all widgets from both `Test` contains same object name
</code></pre>
<p dir="auto">There's another way to differentiate the widgets  other than using their object names when saving their values to a <code>settings.ini</code> file?</p>
<p dir="auto">If no, I'm looking for suggestions in how else I could achieve this, I mean, maybe appending a special character before each widget <code>objectName</code>?</p>
]]></description><link>https://forum.qt.io/topic/144469/how-to-save-settings-of-a-window-that-contains-widgets-with-same-object-name</link><generator>RSS for Node</generator><lastBuildDate>Fri, 10 Apr 2026 17:34:29 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/144469.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 18 Apr 2023 14:58:42 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to How to save settings of a window that contains widgets with same object name? on Tue, 18 Apr 2023 15:43:09 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/ylvy">@<bdi>Ylvy</bdi></a><br />
<a href="https://doc.qt.io/qt-6/qobject.html#findChild" target="_blank" rel="noopener noreferrer nofollow ugc">parentWidget-&gt;findChild&lt;QWidget *&gt;()</a></p>
<p dir="auto">If you really need to "save state" it's more usual to create and save some <em>model</em> than expect to find widgets and know what to save from them.  Up to you.</p>
]]></description><link>https://forum.qt.io/post/755198</link><guid isPermaLink="true">https://forum.qt.io/post/755198</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Tue, 18 Apr 2023 15:43:09 GMT</pubDate></item><item><title><![CDATA[Reply to How to save settings of a window that contains widgets with same object name? on Tue, 18 Apr 2023 15:25:41 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jonb">@<bdi>JonB</bdi></a> there's any 'easy' way to iterate every widget on a ui?</p>
]]></description><link>https://forum.qt.io/post/755193</link><guid isPermaLink="true">https://forum.qt.io/post/755193</guid><dc:creator><![CDATA[Ylvy]]></dc:creator><pubDate>Tue, 18 Apr 2023 15:25:41 GMT</pubDate></item><item><title><![CDATA[Reply to How to save settings of a window that contains widgets with same object name? on Tue, 18 Apr 2023 15:06:41 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/ylvy">@<bdi>Ylvy</bdi></a><br />
Exactly that, you would have to e.g. append a sequence number or a number based on which <code>new Test()</code> you are in to each widget's <code>objectName()</code> if you wish to identify it uniquely across sessions.</p>
]]></description><link>https://forum.qt.io/post/755191</link><guid isPermaLink="true">https://forum.qt.io/post/755191</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Tue, 18 Apr 2023 15:06:41 GMT</pubDate></item></channel></rss>