<?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[reuse of custom C++ class]]></title><description><![CDATA[<p dir="auto">I use the same C++ chart class multiple times in a QML desktop application.  I currently use multiple copies of the class with slightly different names and register them as follows:</p>
<hr />
<p dir="auto">ret = qmlRegisterType&lt;MyClass0&gt;("QwtQuick2", 1, 0, "MyClass0");</p>
<p dir="auto">ret = qmlRegisterType&lt;MyClass1&gt;("QwtQuick2", 1, 0, "MyClass1");</p>
<p dir="auto">ret = qmlRegisterType&lt;MyClass2&gt;("QwtQuick2", 1, 0, "MyClass2");</p>
<p dir="auto">MyClass0 myclass0;<br />
MyClass1 myclass1;<br />
MyClass2 myclass2;</p>
<p dir="auto">Here I connect the signals and slots to the classes for each chart.</p>
<hr />
<p dir="auto">This method functions as needed but I would prefer to not maintain many copies of the same class.  Is there an alternative method?</p>
<p dir="auto">Thanks,<br />
Aaron</p>
]]></description><link>https://forum.qt.io/topic/126876/reuse-of-custom-c-class</link><generator>RSS for Node</generator><lastBuildDate>Mon, 13 Apr 2026 04:31:53 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/126876.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 21 May 2021 21:10:55 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to reuse of custom C++ class on Fri, 21 May 2021 22:14:59 GMT]]></title><description><![CDATA[<p dir="auto">Are you using these in QML?<br />
Just do this in C++:</p>
<pre><code>qmlRegisterType&lt;MyClass&gt;("QwtQuick2", 1, 0, "MyClass");
</code></pre>
<p dir="auto">Then in qml:</p>
<pre><code>import QwtQuick2 1.0
...
MyClass {
  id: myclass0
}
MyClass {
  id: myclass1
}
MyClass {
  id: myclass2
}
</code></pre>
<p dir="auto">You can connect signals in qml via Connections, through on&lt;signal name&gt; callbacks, or actual connect calls to attach to functions in qml.</p>
<p dir="auto">What are you connecting to these objects?</p>
]]></description><link>https://forum.qt.io/post/660955</link><guid isPermaLink="true">https://forum.qt.io/post/660955</guid><dc:creator><![CDATA[fcarney]]></dc:creator><pubDate>Fri, 21 May 2021 22:14:59 GMT</pubDate></item><item><title><![CDATA[Reply to reuse of custom C++ class on Fri, 21 May 2021 22:24:22 GMT]]></title><description><![CDATA[<p dir="auto">Thank you, I will look into what you suggest.<br />
The signals to the instances contain different QVector arrays of data to be displayed.</p>
<p dir="auto">Aaron</p>
]]></description><link>https://forum.qt.io/post/660956</link><guid isPermaLink="true">https://forum.qt.io/post/660956</guid><dc:creator><![CDATA[ABest2]]></dc:creator><pubDate>Fri, 21 May 2021 22:24:22 GMT</pubDate></item><item><title><![CDATA[Reply to reuse of custom C++ class on Fri, 21 May 2021 22:14:59 GMT]]></title><description><![CDATA[<p dir="auto">Are you using these in QML?<br />
Just do this in C++:</p>
<pre><code>qmlRegisterType&lt;MyClass&gt;("QwtQuick2", 1, 0, "MyClass");
</code></pre>
<p dir="auto">Then in qml:</p>
<pre><code>import QwtQuick2 1.0
...
MyClass {
  id: myclass0
}
MyClass {
  id: myclass1
}
MyClass {
  id: myclass2
}
</code></pre>
<p dir="auto">You can connect signals in qml via Connections, through on&lt;signal name&gt; callbacks, or actual connect calls to attach to functions in qml.</p>
<p dir="auto">What are you connecting to these objects?</p>
]]></description><link>https://forum.qt.io/post/660955</link><guid isPermaLink="true">https://forum.qt.io/post/660955</guid><dc:creator><![CDATA[fcarney]]></dc:creator><pubDate>Fri, 21 May 2021 22:14:59 GMT</pubDate></item><item><title><![CDATA[Reply to reuse of custom C++ class on Fri, 21 May 2021 21:21:36 GMT]]></title><description><![CDATA[<p dir="auto">The classes are identical except for the name.  I change the name so that I can connect different signals to each instance.</p>
]]></description><link>https://forum.qt.io/post/660949</link><guid isPermaLink="true">https://forum.qt.io/post/660949</guid><dc:creator><![CDATA[ABest2]]></dc:creator><pubDate>Fri, 21 May 2021 21:21:36 GMT</pubDate></item><item><title><![CDATA[Reply to reuse of custom C++ class on Fri, 21 May 2021 21:12:40 GMT]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">What are the differences between these classes ?</p>
]]></description><link>https://forum.qt.io/post/660948</link><guid isPermaLink="true">https://forum.qt.io/post/660948</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Fri, 21 May 2021 21:12:40 GMT</pubDate></item></channel></rss>