<?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[Slot and Signal problem custom class]]></title><description><![CDATA[<p dir="auto">Hello,</p>
<p dir="auto">I have a problem, i create one class for the differente action and i would like put the different slot on this class. But, when i create the connexion, it use the slot on the class for my ui and not in my class.</p>
<p dir="auto">I explaine : My ui is in the class "MainWindowTracage." and the slot, i put on the class "MainWindowsAction." but, if i create the signal with this line : <strong>connect(window-&gt;ui-&gt;pushButton, SIGNAL(clicked()),action, SLOT(test()) );</strong> on the class MainWindows Action it don't work.<br />
I have this error message :</p>
<pre><code>QObject::connect: No such slot QMainWindow::test() in ..\ihm_tracage\src\mainwindowsaction.cpp:8
QObject::connect:  (sender name:   'pushButton')

</code></pre>
<p dir="auto">Do you have any solution for fixe my problem ?</p>
<p dir="auto">the code :<br />
mainwindowsaction.cpp :</p>
<pre><code class="language-c++">#include "header\mainwindowsaction.h"

MainWindowsAction::MainWindowsAction(MainWindowTracage *window, MainWindowsAffichageMe *affichage, MainWindowsAction *action)
{
    this-&gt;window = window;
    this-&gt;affichage = affichage;

    connect(window-&gt;ui-&gt;pushButton, SIGNAL(clicked()),action, SLOT(MainWindowsAction::test()) );

}

void MainWindowsAction::test()
{
    printf("ok");
}

</code></pre>
<p dir="auto">mainwindowsaction.h :</p>
<pre><code class="language-c++">#ifndef MAINWINDOWSACTION_H
#define MAINWINDOWSACTION_H

#include "mainwindowsaffichageMe.h"
#include "mainwindowtracage.h"

#include "ui_mainwindowtracage.h"

class MainWindowsAction : public QMainWindow
{
    public:
        MainWindowsAction(MainWindowTracage *window, MainWindowsAffichageMe *affichage, MainWindowsAction *action);
    public slots:
        void test();
    private:
        MainWindowTracage *window;
        MainWindowsAffichageMe *affichage;
;
};


</code></pre>
<p dir="auto">thank's for your answer !</p>
]]></description><link>https://forum.qt.io/topic/131801/slot-and-signal-problem-custom-class</link><generator>RSS for Node</generator><lastBuildDate>Sun, 27 Sep 2026 20:23:30 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/131801.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 08 Nov 2021 10:53:37 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Slot and Signal problem custom class on Mon, 08 Nov 2021 13:06:14 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/vin212">@<bdi>vin212</bdi></a> said in <a href="/post/689047">Slot and Signal problem custom class</a>:</p>
<blockquote>
<p dir="auto">I change for :</p>
</blockquote>
<pre><code>    connect(window-&gt;ui-&gt;pushButton, &amp;QPushButton::clicked,this, &amp;MainWindowsAction::test );
</code></pre>
<blockquote>
<p dir="auto">and i add Q_OBJECT<br />
but i have an other error message :</p>
</blockquote>
<blockquote>
<p dir="auto">Yes, it's maybe this problem, i recompile and it's work<br />
Thank's for your answers</p>
</blockquote>
<p dir="auto">After adding <code>Q_OBJECT</code> to a class, you need rerun <strong>moc</strong> (Meta-Object Compiler).<br />
Take a look at following links for more details!</p>
<ul>
<li><a href="https://doc.qt.io/qt-5/moc.html" target="_blank" rel="noopener noreferrer nofollow ugc">https://doc.qt.io/qt-5/moc.html</a></li>
<li><a href="https://doc.qt.io/qt-5/why-moc.html" target="_blank" rel="noopener noreferrer nofollow ugc">https://doc.qt.io/qt-5/why-moc.html</a></li>
</ul>
]]></description><link>https://forum.qt.io/post/689082</link><guid isPermaLink="true">https://forum.qt.io/post/689082</guid><dc:creator><![CDATA[KroMignon]]></dc:creator><pubDate>Mon, 08 Nov 2021 13:06:14 GMT</pubDate></item><item><title><![CDATA[Reply to Slot and Signal problem custom class on Mon, 08 Nov 2021 12:47:19 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/vin212">@<bdi>vin212</bdi></a> said in <a href="/post/689040">Slot and Signal problem custom class</a>:</p>
<blockquote>
<p dir="auto">and i add Q_OBJECT</p>
</blockquote>
<p dir="auto">Regardless of any other issues.  Any time you add <code>Q_OBJECT</code> to an already defined and compiled class you must do a complete rebuild.  This is a known practicality.  If you do not, you are liable to get precisely the <code>vtable</code> error you got for that class.</p>
]]></description><link>https://forum.qt.io/post/689068</link><guid isPermaLink="true">https://forum.qt.io/post/689068</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Mon, 08 Nov 2021 12:47:19 GMT</pubDate></item><item><title><![CDATA[Reply to Slot and Signal problem custom class on Mon, 08 Nov 2021 11:38:41 GMT]]></title><description><![CDATA[<p dir="auto">@J-Hilk</p>
<p dir="auto">Yes, it's maybe this problem, i recompile and it's work</p>
<p dir="auto">Thank's for your answers</p>
]]></description><link>https://forum.qt.io/post/689047</link><guid isPermaLink="true">https://forum.qt.io/post/689047</guid><dc:creator><![CDATA[vin212]]></dc:creator><pubDate>Mon, 08 Nov 2021 11:38:41 GMT</pubDate></item><item><title><![CDATA[Reply to Slot and Signal problem custom class on Mon, 08 Nov 2021 11:27:48 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/vin212">@<bdi>vin212</bdi></a><br />
seems like the compiler was unable to properly construct the polymorphism relations</p>
<p dir="auto">My bet would be because your only constructor<br />
<code>MainWindowsAction(MainWindowTracage *window, MainWindowsAffichageMe *affichage, MainWindowsAction *action);</code></p>
<p dir="auto">requieres a pointer to an other instance of your class.</p>
]]></description><link>https://forum.qt.io/post/689042</link><guid isPermaLink="true">https://forum.qt.io/post/689042</guid><dc:creator><![CDATA[J.Hilk]]></dc:creator><pubDate>Mon, 08 Nov 2021 11:27:48 GMT</pubDate></item><item><title><![CDATA[Reply to Slot and Signal problem custom class on Mon, 08 Nov 2021 11:26:56 GMT]]></title><description><![CDATA[<p dir="auto">Ok !</p>
<p dir="auto">I change for :</p>
<pre><code class="language-c++">connect(window-&gt;ui-&gt;pushButton, &amp;QPushButton::clicked,this, &amp;MainWindowsAction::test );


</code></pre>
<p dir="auto">and i add Q_OBJECT<br />
but i have an other error message :</p>
<pre><code>mainwindowsaction.cpp:3: erreur : undefined reference to `vtable for MainWindowsAction'
debug/mainwindowsaction.o: In function `ZN17MainWindowsActionC2EP17MainWindowTracageP22MainWindowsAffichageMePS_':
mainwindowsaction.cpp:3: undefined reference to `vtable for MainWindowsAction'
</code></pre>
<p dir="auto">I add the destructor and is the same.</p>
]]></description><link>https://forum.qt.io/post/689040</link><guid isPermaLink="true">https://forum.qt.io/post/689040</guid><dc:creator><![CDATA[vin212]]></dc:creator><pubDate>Mon, 08 Nov 2021 11:26:56 GMT</pubDate></item><item><title><![CDATA[Reply to Slot and Signal problem custom class on Mon, 08 Nov 2021 11:07:42 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/vin212">@<bdi>vin212</bdi></a> you're missing <code>Q_OBJECT</code>macro in your header, old qt4 connect syntax does not work without it.<br />
also <code>action </code> is wrong here as receiver object, it ought to be <code>this</code></p>
<p dir="auto">all in all its this quite wrong:</p>
<pre><code>connect(window-&gt;ui-&gt;pushButton, SIGNAL(clicked()),action, SLOT(MainWindowsAction::test()) );
</code></pre>
<p dir="auto">thats mixing syntaxes</p>
<pre><code>connect(window-&gt;ui-&gt;pushButton, SIGNAL(clicked()),this, SLOT(test()) );
</code></pre>
<p dir="auto">or preferably</p>
<pre><code>connect(window-&gt;ui-&gt;pushButton, &amp;QPushButton::clicked, this ,&amp;MainWindowsAction::test );
</code></pre>
]]></description><link>https://forum.qt.io/post/689037</link><guid isPermaLink="true">https://forum.qt.io/post/689037</guid><dc:creator><![CDATA[J.Hilk]]></dc:creator><pubDate>Mon, 08 Nov 2021 11:07:42 GMT</pubDate></item><item><title><![CDATA[Reply to Slot and Signal problem custom class on Mon, 08 Nov 2021 11:01:02 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/vin212">@<bdi>vin212</bdi></a><br />
Start by changing over to <a href="https://wiki.qt.io/New_Signal_Slot_Syntax" target="_blank" rel="noopener noreferrer nofollow ugc">New Signal Slot Syntax</a> instead of using your <code>SIGNAL</code>/<code>SLOT()</code> macros, the compile-time errors you will receive while you get your code right will be much more helpful.</p>
<p dir="auto">From the error message you show you cannot have <code>action, SLOT(MainWindowsAction::test())</code> in your <code>connect()</code>.  And/or you reference a <code>QMainWindow::test()</code> on the line it tells you, and there is no such slot.</p>
]]></description><link>https://forum.qt.io/post/689035</link><guid isPermaLink="true">https://forum.qt.io/post/689035</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Mon, 08 Nov 2021 11:01:02 GMT</pubDate></item></channel></rss>