<?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[Questions about the use of QML and C++ and their connection]]></title><description><![CDATA[<p dir="auto">I am wondering how I should use QML and C++.<br />
Each has its own capabilities and advantages, and it is possible to connect them.</p>
<p dir="auto">I am currently using QML for screen displays and C++ for calculations and other processing.<br />
However, I often end up with processes that call the same classes and functions over and over.<br />
What connections or structures should be made to avoid inadvertent redefinitions?</p>
]]></description><link>https://forum.qt.io/topic/137727/questions-about-the-use-of-qml-and-c-and-their-connection</link><generator>RSS for Node</generator><lastBuildDate>Wed, 10 Jun 2026 18:41:49 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/137727.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 07 Jul 2022 02:42:17 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Questions about the use of QML and C++ and their connection on Thu, 07 Jul 2022 19:21:06 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/egusa">@<bdi>egusa</bdi></a> said in <a href="/post/720384">Questions about the use of QML and C++ and their connection</a>:</p>
<blockquote>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sierdzio">@<bdi>sierdzio</bdi></a><br />
[...] it will be initialized again. [...]</p>
</blockquote>
<p dir="auto">Well, that part is up to you, really :-) You can take the instance from QML (pass it via signal, for example), or you can use your C++ object as a singleton and do the initialization on C++ part. Or you can init your object in main.cpp, pass it to QML as context property, then pass <em>the same pointer</em> down your C++ code to where you need it. There are many ways to get around this problem.</p>
]]></description><link>https://forum.qt.io/post/720495</link><guid isPermaLink="true">https://forum.qt.io/post/720495</guid><dc:creator><![CDATA[sierdzio]]></dc:creator><pubDate>Thu, 07 Jul 2022 19:21:06 GMT</pubDate></item><item><title><![CDATA[Reply to Questions about the use of QML and C++ and their connection on Thu, 07 Jul 2022 17:44:35 GMT]]></title><description><![CDATA[<p dir="auto">I'm only taking a wild guess here....</p>
<p dir="auto">But if the tactic you're using for exposing the C++ object to QML involves something like this:</p>
<pre><code>// assume: QQmlEngine* engine 
// assume: "this" is your custom C++ subtype of QObject that you expose to QML

    engine-&gt;rootContext()-&gt;setContextProperty( "myCustomViewModel", this );
</code></pre>
<p dir="auto">Then if you are doing that each time you instantiate an instance of your type, then you would be overwriting the reference that your QML has for "myCustomViewModel".</p>
<p dir="auto">This is all wild conjecture on my part, because we really need more code snippets to understand. However, my conjecture matches your real-life codebase, then the solution is to de-couple instantiation from <code>setContextProperty</code>. Then you could instantiate many objects, but only <code>setContextProperty</code> on one to export that one to QML.</p>
]]></description><link>https://forum.qt.io/post/720479</link><guid isPermaLink="true">https://forum.qt.io/post/720479</guid><dc:creator><![CDATA[KH-219Design]]></dc:creator><pubDate>Thu, 07 Jul 2022 17:44:35 GMT</pubDate></item><item><title><![CDATA[Reply to Questions about the use of QML and C++ and their connection on Thu, 07 Jul 2022 07:59:47 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sierdzio">@<bdi>sierdzio</bdi></a><br />
If I try to use a C++ class from QML.<br />
If I use that class in a class on another C++, it will be initialized again.<br />
In such a case, the class can no longer be used from QML.</p>
]]></description><link>https://forum.qt.io/post/720384</link><guid isPermaLink="true">https://forum.qt.io/post/720384</guid><dc:creator><![CDATA[egusa]]></dc:creator><pubDate>Thu, 07 Jul 2022 07:59:47 GMT</pubDate></item><item><title><![CDATA[Reply to Questions about the use of QML and C++ and their connection on Thu, 07 Jul 2022 05:29:51 GMT]]></title><description><![CDATA[<p dir="auto">Can you give a short example? I don't understand what you mean with:</p>
<blockquote>
<p dir="auto">However, I often end up with processes that call the same classes and functions over and over.<br />
What connections or structures should be made to avoid inadvertent redefinitions?</p>
</blockquote>
]]></description><link>https://forum.qt.io/post/720361</link><guid isPermaLink="true">https://forum.qt.io/post/720361</guid><dc:creator><![CDATA[sierdzio]]></dc:creator><pubDate>Thu, 07 Jul 2022 05:29:51 GMT</pubDate></item></channel></rss>