<?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[Signal from Application class?]]></title><description><![CDATA[<p dir="auto">I've been writing an application for several weeks now, the main class is derived from <strong>QApplication</strong>.</p>
<pre><code>class Trainer : public QApplication
</code></pre>
<p dir="auto">Today I tried to implement a signal from the main application so that if an error occurs it emits a signal:</p>
<pre><code>signals:
    void dbError(const QSqlError&amp; crErr);
</code></pre>
<p dir="auto">When building this resulted in:</p>
<pre><code>C2338: No Q_OBJECT in the class with the signal
</code></pre>
<p dir="auto">So I added <strong>Q_OBJECT</strong> to the class and rebuilt, now the errors are:</p>
<pre><code>LNK2019: unresolved external symbol "public void __thiscall Trainer::dbError(class QSqlError const &amp;) ...
LNK2001: unresolved external symbol "public void __thiscall Trainer::dbError(class QSqlError const &amp;) ...
</code></pre>
<p dir="auto">This is the actual emit in the class:</p>
<pre><code>emit Trainer::mspApp-&gt;dbError(err);
</code></pre>
<p dir="auto"><strong>mspApp</strong> is defined as:</p>
<pre><code>static Trainer* mspApp;
</code></pre>
<p dir="auto">Which is in the <strong>Trainer</strong> class and in the module:</p>
<pre><code>Trainer* Trainer::mspApp = nullptr;
</code></pre>
<p dir="auto">This static pointer is initialised in the class constructor:</p>
<pre><code>Trainer::mspApp = this;
</code></pre>
<p dir="auto">What am I not doing?</p>
]]></description><link>https://forum.qt.io/topic/126745/signal-from-application-class</link><generator>RSS for Node</generator><lastBuildDate>Sun, 12 Apr 2026 21:54:19 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/126745.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 18 May 2021 07:46:19 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Signal from Application class? on Tue, 18 May 2021 08:56:43 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/660228">Signal from Application class?</a>:</p>
<blockquote>
<p dir="auto">So I added Q_OBJECT to the class and rebuilt, now the errors are:<br />
LNK2019: unresolved external symbol "public void __thiscall Trainer::dbError(class QSqlError const &amp;) ...<br />
LNK2001: unresolved external symbol "public void __thiscall Trainer::dbError(class QSqlError const &amp;) ...</p>
</blockquote>
<p dir="auto">The only reason I am aware about for this issue is that the <strong>MOC</strong> has not been called.</p>
<p dir="auto">For QMake projects, you just have to rerun QMake (Build =&gt; run qmake), and rebuild the project.<br />
For CMake projects, I don't know, there must be something equivalent.</p>
<p dir="auto">Or simply delete the build directory.</p>
]]></description><link>https://forum.qt.io/post/660254</link><guid isPermaLink="true">https://forum.qt.io/post/660254</guid><dc:creator><![CDATA[KroMignon]]></dc:creator><pubDate>Tue, 18 May 2021 08:56:43 GMT</pubDate></item><item><title><![CDATA[Reply to Signal from Application class? on Tue, 18 May 2021 08:14:56 GMT]]></title><description><![CDATA[<p dir="auto">@J-Hilk , ok, noted for future, but not an issue here as I'm creating a pointer to my own instance.</p>
]]></description><link>https://forum.qt.io/post/660243</link><guid isPermaLink="true">https://forum.qt.io/post/660243</guid><dc:creator><![CDATA[SPlatten]]></dc:creator><pubDate>Tue, 18 May 2021 08:14:56 GMT</pubDate></item><item><title><![CDATA[Reply to Signal from Application class? on Tue, 18 May 2021 08:11:40 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/660238">Signal from Application class?</a>:</p>
<blockquote>
<p dir="auto">thank you, the reason I added my own static point is so I don't have to put in static casts where its used in order to reference the signals.</p>
</blockquote>
<p dir="auto">C++ dynamic_cast() or qobject_cast()  NOT static_cast!</p>
<p dir="auto">My heart 😱<br />
😉</p>
]]></description><link>https://forum.qt.io/post/660240</link><guid isPermaLink="true">https://forum.qt.io/post/660240</guid><dc:creator><![CDATA[J.Hilk]]></dc:creator><pubDate>Tue, 18 May 2021 08:11:40 GMT</pubDate></item><item><title><![CDATA[Reply to Signal from Application class? on Tue, 18 May 2021 08:08:50 GMT]]></title><description><![CDATA[<p dir="auto">@J-Hilk, thank you, the reason I added my own static point is so I don't have to put in static casts where its used in order to reference the signals.</p>
<p dir="auto">Sorry, again <strong>Application</strong> is supposed to read <strong>QApplication</strong> that was a typo adding this post, the laptop I'm using on has issues and cannot post to this forum.  So I have to type it all in on my iMac.</p>
]]></description><link>https://forum.qt.io/post/660238</link><guid isPermaLink="true">https://forum.qt.io/post/660238</guid><dc:creator><![CDATA[SPlatten]]></dc:creator><pubDate>Tue, 18 May 2021 08:08:50 GMT</pubDate></item><item><title><![CDATA[Reply to Signal from Application class? on Tue, 18 May 2021 08:00:29 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/splatten">@<bdi>SPlatten</bdi></a> you don't have to reinvent the wheel you know, especially in relation to static QObjects, that are tricky in their own right. Especially as the instantiation order is important</p>
<p dir="auto">you're deriving from QApplication, so you have the qApp macro at your disposal</p>
<pre><code>#define qApp QCoreApplication::instance()
</code></pre>
<p dir="auto">or use the QCoreApplication::instance() call direct. and object cast it.</p>
<p dir="auto">If you're copy pasted this, than you have an error in your code, as this should be QApplication not Application</p>
<pre><code>class Trainer : public Application
</code></pre>
]]></description><link>https://forum.qt.io/post/660236</link><guid isPermaLink="true">https://forum.qt.io/post/660236</guid><dc:creator><![CDATA[J.Hilk]]></dc:creator><pubDate>Tue, 18 May 2021 08:00:29 GMT</pubDate></item><item><title><![CDATA[Reply to Signal from Application class? on Tue, 18 May 2021 07:56:42 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jsulm">@<bdi>jsulm</bdi></a> , yes, cleaned, then remake then rebuild, before posting here.</p>
]]></description><link>https://forum.qt.io/post/660234</link><guid isPermaLink="true">https://forum.qt.io/post/660234</guid><dc:creator><![CDATA[SPlatten]]></dc:creator><pubDate>Tue, 18 May 2021 07:56:42 GMT</pubDate></item><item><title><![CDATA[Reply to Signal from Application class? on Tue, 18 May 2021 07:52:31 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/660228">Signal from Application class?</a>:</p>
<blockquote>
<p dir="auto">What am I not doing?</p>
</blockquote>
<p dir="auto">Did you do complete rebuild after adding Q_OBJECT macro?</p>
]]></description><link>https://forum.qt.io/post/660230</link><guid isPermaLink="true">https://forum.qt.io/post/660230</guid><dc:creator><![CDATA[jsulm]]></dc:creator><pubDate>Tue, 18 May 2021 07:52:31 GMT</pubDate></item></channel></rss>