<?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[Get values from nested properties]]></title><description><![CDATA[<p dir="auto">I'm trying to read values from nested properties:</p>
<pre><code>// root class ...
class TestRootClass : public QObject
{
    Q_OBJECT
    Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
    Q_PROPERTY(TestPropertyObject test READ test WRITE setTest NOTIFY testChanged)
...
}

// class of property in root class
class TestPropertyObject
{
    Q_GADGET
    Q_PROPERTY(QString name READ name WRITE setName)
    Q_PROPERTY(int count READ count WRITE setCount)
...
}
</code></pre>
<p dir="auto">I want to read Q_PROPERTY values from any arbitrary object but taking into account the property-hierarchy as far as possible and got this far:</p>
<pre><code>QMap(
	("applicationName", QVariant(QString, "applicationName"))
	("applicationVersion", QVariant(QString, "applicationVersion"))
	("objectName", QVariant(QString, "objectName"))
	("organizationDomain", QVariant(QString, "organizationDomain"))
	("organizationName", QVariant(QString, "organizationName"))
	("quitLockEnabled", QVariant(QString, "quitLockEnabled"))
	("name", QVariant(QString, "name"))
	("test", QVariant(QVariantMap, QMap(
		("count", QVariant(QString, "count"))
		("name", QVariant(QString, "name"))
	)))
)
</code></pre>
<p dir="auto">The problem is that this QMap is based on staticMetaObject informations and therefor there are no values available.</p>
<p dir="auto">Any idea how i can retrieve the values of these nested properties?</p>
<p dir="auto">BR</p>
]]></description><link>https://forum.qt.io/topic/63423/get-values-from-nested-properties</link><generator>RSS for Node</generator><lastBuildDate>Thu, 16 Apr 2026 21:05:06 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/63423.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 27 Jan 2016 15:56:51 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Get values from nested properties on Thu, 28 Jan 2016 08:37:46 GMT]]></title><description><![CDATA[<p dir="auto">Thanks for your reply.<br />
The problem is that i can't get a proper object from a property (- just QVariant or void*).<br />
So how can i access the MetaObject of this property object?</p>
]]></description><link>https://forum.qt.io/post/310018</link><guid isPermaLink="true">https://forum.qt.io/post/310018</guid><dc:creator><![CDATA[ttuna]]></dc:creator><pubDate>Thu, 28 Jan 2016 08:37:46 GMT</pubDate></item><item><title><![CDATA[Reply to Get values from nested properties on Wed, 27 Jan 2016 21:39:38 GMT]]></title><description><![CDATA[<p dir="auto">Hi! I'm not sure what you want to achieve. You can retrieve every QObject's attached QMetaObject with</p>
<pre><code>QObject *obj = new TestRootClass;
QMetaObject *mo = obj-&gt;metaObject(); 
</code></pre>
<p dir="auto">You can now access all its properties (with <code>property(index)</code>) and then read the value of this property from your actual object (<code>.read(obj)</code>).</p>
<pre><code>
for (int i = mo-&gt;propertyOffset(); i &lt; mo-&gt;propertyCount(); ++i) {
    QVariant tmp = mo-&gt;property(i).read(obj);
    qDebug() &lt;&lt; tmp;
}
</code></pre>
<p dir="auto">Hope it helps!</p>
]]></description><link>https://forum.qt.io/post/309958</link><guid isPermaLink="true">https://forum.qt.io/post/309958</guid><dc:creator><![CDATA[[[global:former-user]]]]></dc:creator><pubDate>Wed, 27 Jan 2016 21:39:38 GMT</pubDate></item></channel></rss>