<?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[Is the documentation correct for QMetaObject Class | Qt 4.8 ?]]></title><description><![CDATA[<p dir="auto">On this page:<br />
<a href="https://doc.qt.io/archives/qt-4.8/qmetaobject.html#property" target="_blank" rel="noopener noreferrer nofollow ugc">https://doc.qt.io/archives/qt-4.8/qmetaobject.html#property</a></p>
<p dir="auto">The sample code shows:</p>
<pre><code>for(int i = metaObject-&gt;propertyOffset(); i &lt; metaObject-&gt;propertyCount(); ++i)
</code></pre>
<p dir="auto">Is this correct?  Because in my simple code that I've created:</p>
<pre><code>const QMetaObject* cpobjMO(metaObject());
for( int i=cpobjMO-&gt;propertyOffset(); i&lt;cpobjMO-&gt;propertyCount(); ++i )
</code></pre>
<p dir="auto">I have already added a property to the class in the constructor using:</p>
<pre><code>setProperty(crstrMember.toLatin1().data(), crvarData);
</code></pre>
<p dir="auto">Where <strong>crstrMember</strong> contains <strong>"Hello"</strong> and <strong>crvarData</strong> contains <strong>"World"</strong>.    When I get to the loop, both <strong>propertyOffset</strong> and <strong>propertyCount</strong> return 1, so it will not iterate at all.</p>
]]></description><link>https://forum.qt.io/topic/134413/is-the-documentation-correct-for-qmetaobject-class-qt-4-8</link><generator>RSS for Node</generator><lastBuildDate>Thu, 14 May 2026 12:13:59 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/134413.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 17 Feb 2022 10:37:52 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Is the documentation correct for QMetaObject Class | Qt 4.8 ? on Thu, 17 Feb 2022 11:36:33 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/splatten">@<bdi>SPlatten</bdi></a> said in <a href="/post/702981">Is the documentation correct for QMetaObject Class | Qt 4.8 ?</a>:</p>
<blockquote>
<p dir="auto">See above results with comments.</p>
</blockquote>
<p dir="auto">Oh, sorry but I made the same mistake as you!<br />
This only works for property which have been declared with <code>Q_PROPERTY</code>, and therefore added in the QMetaObject create by the MOC!!</p>
<p dir="auto">What you are looking for is <code>QObject::dynamicPropertyNames()</code> (cf <a href="https://doc.qt.io/archives/qt-4.8/qobject.html#dynamicPropertyNames" target="_blank" rel="noopener noreferrer nofollow ugc">https://doc.qt.io/archives/qt-4.8/qobject.html#dynamicPropertyNames</a>)</p>
]]></description><link>https://forum.qt.io/post/702982</link><guid isPermaLink="true">https://forum.qt.io/post/702982</guid><dc:creator><![CDATA[KroMignon]]></dc:creator><pubDate>Thu, 17 Feb 2022 11:36:33 GMT</pubDate></item><item><title><![CDATA[Reply to Is the documentation correct for QMetaObject Class | Qt 4.8 ? on Thu, 17 Feb 2022 11:39:24 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/kromignon">@<bdi>KroMignon</bdi></a> , Thank you, I was starting to think it had to be something very fundamental like that...I think some notes in the documentation would be useful, since the functions are called <strong>property</strong> and <strong>setProperty</strong>.</p>
]]></description><link>https://forum.qt.io/post/702983</link><guid isPermaLink="true">https://forum.qt.io/post/702983</guid><dc:creator><![CDATA[SPlatten]]></dc:creator><pubDate>Thu, 17 Feb 2022 11:39:24 GMT</pubDate></item><item><title><![CDATA[Reply to Is the documentation correct for QMetaObject Class | Qt 4.8 ? on Thu, 17 Feb 2022 11:36:33 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/splatten">@<bdi>SPlatten</bdi></a> said in <a href="/post/702981">Is the documentation correct for QMetaObject Class | Qt 4.8 ?</a>:</p>
<blockquote>
<p dir="auto">See above results with comments.</p>
</blockquote>
<p dir="auto">Oh, sorry but I made the same mistake as you!<br />
This only works for property which have been declared with <code>Q_PROPERTY</code>, and therefore added in the QMetaObject create by the MOC!!</p>
<p dir="auto">What you are looking for is <code>QObject::dynamicPropertyNames()</code> (cf <a href="https://doc.qt.io/archives/qt-4.8/qobject.html#dynamicPropertyNames" target="_blank" rel="noopener noreferrer nofollow ugc">https://doc.qt.io/archives/qt-4.8/qobject.html#dynamicPropertyNames</a>)</p>
]]></description><link>https://forum.qt.io/post/702982</link><guid isPermaLink="true">https://forum.qt.io/post/702982</guid><dc:creator><![CDATA[KroMignon]]></dc:creator><pubDate>Thu, 17 Feb 2022 11:36:33 GMT</pubDate></item><item><title><![CDATA[Reply to Is the documentation correct for QMetaObject Class | Qt 4.8 ? on Thu, 17 Feb 2022 11:35:28 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/kromignon">@<bdi>KroMignon</bdi></a> , I'm making some kind of fundamental mistake because I've just made another change to test and validate:</p>
<pre><code>clsJSON::clsJSON(QObject* pParent) : QObject(pParent) {
}
void clsJSON::insert(const QString&amp; crstrMember, const QVariant&amp; crvarData) {
    if ( crstrMember.isEmpty() == true || crvarData.isValid() != true ) {
        return;
    }
    setProperty(crstrMember.toLatin1().data(), crvarData);
}
QString clsJSON::toString() {
    const QMetaObject* cpobjMO(metaObject());
    int intOffset = cpobjMO-&gt;propertyOffset()  // returns 1
       ,intCount = cpobjMO-&gt;propertyCount();    // returns 1
    const QString cstrTest("Another");
    const QVariant cvarData("test");
    insert(cstrTest, cvarData);
    QVariant varP1(property("HELLO"));       // Works and varP1 contains "WORLD"
    QVariant varP2(property("Another"));    // Also works varP2 contains "test"
    intOffset = cpobjMO-&gt;propertyOffset()  // still returns 1
    intCount = cpobjMO-&gt;propertyCount();    // still returns 1
    for( int i=cpobjMO-&gt;propertyOffset(); i&lt;cpobjMO-&gt;propertyCount(); ++i ) {
        ...  
    }
    return ...;
}
</code></pre>
<p dir="auto">See above results with comments.</p>
<p dir="auto">[Edit] See additional to lines where I get the property data inserted and verify it is correct, yet the propertyOffset and propertyCount are both still 1.</p>
]]></description><link>https://forum.qt.io/post/702981</link><guid isPermaLink="true">https://forum.qt.io/post/702981</guid><dc:creator><![CDATA[SPlatten]]></dc:creator><pubDate>Thu, 17 Feb 2022 11:35:28 GMT</pubDate></item><item><title><![CDATA[Reply to Is the documentation correct for QMetaObject Class | Qt 4.8 ? on Thu, 17 Feb 2022 11:03:16 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/kromignon">@<bdi>KroMignon</bdi></a> , yes, my test code is very simple:</p>
<pre><code>clsJSON objDemo;
objDemo.insert("HELLO", "WORLD");
QString strJSON(objDemo.toString());
qDebug() &lt;&lt; strJSON;
</code></pre>
<p dir="auto">The class itself:</p>
<pre><code>clsJSON::clsJSON(QObject* pParent) : QObject(pParent) {
}
void clsJSON::insert(const QString&amp; crstrMember, const QVariant&amp; crvarData) {
    if ( crstrMember.isEmpty() == true || crvarData.isValid() != true ) {
        return;
    }
    setProperty(crstrMember.toLatin1().data(), crvarData);
}
QString clsJSON::toString() const {
    const QMetaObject* cpobjMO(metaObject());
    for( int i=cpobjMO-&gt;propertyOffset(); i&lt;cpobjMO-&gt;propertyCount(); ++i ) {
        ...  
    }
    return ...;
}
</code></pre>
<p dir="auto"><strong>toString</strong> is not compete yet, but the loop isn't getting iterated at all, I've checked and as posted <strong>propertyOffset</strong> and <strong>propertyCount</strong> both equal 1.</p>
]]></description><link>https://forum.qt.io/post/702979</link><guid isPermaLink="true">https://forum.qt.io/post/702979</guid><dc:creator><![CDATA[SPlatten]]></dc:creator><pubDate>Thu, 17 Feb 2022 11:03:16 GMT</pubDate></item><item><title><![CDATA[Reply to Is the documentation correct for QMetaObject Class | Qt 4.8 ? on Thu, 17 Feb 2022 10:54:27 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/splatten">@<bdi>SPlatten</bdi></a> said in <a href="/post/702971">Is the documentation correct for QMetaObject Class | Qt 4.8 ?</a>:</p>
<blockquote>
<p dir="auto">Where crstrMember contains "Hello" and crvarData contains "World".    When I get to the loop, both propertyOffset and propertyCount return 1, so it will not iterate at all.</p>
</blockquote>
<p dir="auto">Are you sure you are testing on the right object instance?<br />
Note: propertyOffset = 1, which is normal, property 0 is the name() property of the QObject (cf. <a href="https://doc.qt.io/archives/qt-4.8/qmetaobject.html#propertyOffset" target="_blank" rel="noopener noreferrer nofollow ugc">https://doc.qt.io/archives/qt-4.8/qmetaobject.html#propertyOffset</a>).</p>
<pre><code>setProperty("Hello", "world");
const QMetaObject* cpobjMO(metaObject());
for( int i=cpobjMO-&gt;propertyOffset(); i&lt;cpobjMO-&gt;propertyCount(); ++i )
    qDebug() &lt;&lt; "Found" &lt;&lt; i &lt;&lt; "as" &lt;&lt; QString::fromLatin1(cpobjMO-&gt;property(i).name());
</code></pre>
]]></description><link>https://forum.qt.io/post/702977</link><guid isPermaLink="true">https://forum.qt.io/post/702977</guid><dc:creator><![CDATA[KroMignon]]></dc:creator><pubDate>Thu, 17 Feb 2022 10:54:27 GMT</pubDate></item></channel></rss>