<?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[Order of multiple C++ QML_ELEMENT instantiation]]></title><description><![CDATA[<p dir="auto">I am learning Qt 6 Quick for about a month now.  I have the following classes:</p>
<pre><code>class Class1 : public QObject {
Q_OBJECT
Q_SINGLETON
Q_ELEMENT
....
};

class Class2 : public QObject {
Q_OBJECT
Q_SINGLETON
Q_ELEMENT
....
};
</code></pre>
<p dir="auto">I understand that when using qmlRegisterSingletonInstance or other methods specified in main.cpp</p>
<pre><code>// main.cpp
...
Class1 instance1;
Class2 instance2;
qmlRegisterSingletonInstance("MyObject1", 1, 0, "MyApi1", instance1.get());
qmlRegisterSingletonInstance("MyObject2", 1, 0, "MyApi2", instance2.get());
...

</code></pre>
<p dir="auto">I can specify the order of the instantiations.</p>
<p dir="auto">How about when using macro QML_ELEMENT and QML_SINGLETON? Are they instantiated in the order of files inclusion in CMakeLists.txt qt_add_qml_module ?  or does it happen during import statements in qml file?</p>
]]></description><link>https://forum.qt.io/topic/165082/order-of-multiple-c-qml_element-instantiation</link><generator>RSS for Node</generator><lastBuildDate>Tue, 15 Sep 2026 00:07:45 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/165082.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 11 Sep 2026 07:22:23 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Order of multiple C++ QML_ELEMENT instantiation on Mon, 14 Sep 2026 11:40:23 GMT]]></title><description><![CDATA[<p dir="auto">Consider the order to be undefined, and something you shouldn't rely on. To be honest, that's the same as if you were to use <code>qmlRegisterSingletonType</code> using the imperative API; there's no instantiation at the point of the registration, that will happen later when the engine actually needs the singleton (and "needs" is intentionally vague here).</p>
<p dir="auto">If you have an order-dependent construction, you should (in that order of preferability)<br />
a) consider if you can move away from that pattern, or<br />
b) use <a href="https://doc-snapshots.qt.io/qt6-dev/qqmlengine.html#setExternalSingletonInstance" target="_blank" rel="noopener noreferrer nofollow ugc">https://doc-snapshots.qt.io/qt6-dev/qqmlengine.html#setExternalSingletonInstance</a> once 6.12 is  released or<br />
c) keep using imperative registration.</p>
]]></description><link>https://forum.qt.io/post/840145</link><guid isPermaLink="true">https://forum.qt.io/post/840145</guid><dc:creator><![CDATA[FKosmale]]></dc:creator><pubDate>Mon, 14 Sep 2026 11:40:23 GMT</pubDate></item></channel></rss>