<?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[Signals and Slots between two classes]]></title><description><![CDATA[<p dir="auto">I am facing problem on connecting the signals between two classes. I have create slots, signals and connected the same but signals are not received in slots. Could you please help me out to find the problem. Please find the code which I have implemented.</p>
<p dir="auto">Form.H</p>
<pre><code class="language-cpp">#ifndef FORM_H
#define FORM_H

#include &lt;QWidget&gt;
#include "test.h"

namespace Ui {
class Form;
}

class Form : public QWidget
{
    Q_OBJECT

public:
    explicit Form(QWidget *parent = nullptr);
    ~Form();


signals:
    void valueChanged(int newValue);

private slots:
    void on_button_clicked();

    void off_button_clicked();

private:
    Ui::Form *ui;
    int value;
    Test obj;
};

#endif // FORM_H
</code></pre>
<p dir="auto">Test.h</p>
<pre><code class="language-cpp">#ifndef TEST_H
#define TEST_H

#include &lt;QtCore/qglobal.h&gt;
#if QT_VERSION &gt;= 0x050000
#include &lt;QtWidgets/QWidget&gt;
#else
#include &lt;QtGui/QWidget&gt;
#endif

class Test : public QWidget
{
    Q_OBJECT

    public:
        explicit Test(QWidget *parent = nullptr);
        void EnableImage(int value);

signals:
        void ValueChanged(int value);
};

#endif // TEST_H
</code></pre>
<p dir="auto">widget.h</p>
<pre><code class="language-cpp">#ifndef WIDGET_H
#define WIDGET_H

#include &lt;QWidget&gt;
#include &lt;QLabel&gt;


namespace Ui {
class Widget;
}

class Widget : public QWidget
{
    Q_OBJECT



public:
    explicit Widget(QWidget *parent = nullptr);
    ~Widget();

    QLabel *Picture;

public slots:
    void setValue(int value);

public:
    Ui::Widget *ui;
};

#endif // WIDGET_H
</code></pre>
<p dir="auto">form.cpp</p>
<pre><code class="language-cpp">#include "form.h"
#include "ui_form.h"

Form::Form(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Form)
{
    ui-&gt;setupUi(this);
    value = 0;
    Test obj;
}

Form::~Form()
{
    delete ui;
}

void Form::on_button_clicked()
{
    value = 1;
    obj.EnableImage(value);
}

void Form::off_button_clicked()
{
    value = 0;
    obj.EnableImage(value);
}
</code></pre>
<p dir="auto">main.cpp</p>
<pre><code class="language-cpp">#include "widget.h"
#include "form.h"
#include "test.h"
#include &lt;QApplication&gt;
#include &lt;QObject&gt;


extern Widget w;
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    Widget w;
    Form f;
    Test t;


    w.show();
    f.show();

    // help show windows apart
    f.move(w.geometry().left() + 50,w.geometry().top() + 50);

    QObject::connect(&amp;t, SIGNAL(valueChanged(int)),
                         &amp;w, SLOT(setValue(int)));


    return a.exec();
}
</code></pre>
<p dir="auto">test.cpp</p>
<pre><code class="language-cpp">#include "test.h"

Test::Test(QWidget *parent) : QWidget(parent)
{

}

void Test::EnableImage(int value)
{
    emit ValueChanged(value);
}

widget.cpp
#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui-&gt;setupUi(this);
    Picture = ui-&gt;image;
    Picture-&gt;hide();

}

void Widget::setValue(int value)
{
    if(value == 0)
    {
        Picture-&gt;hide();
    }
    else
    {
        Picture-&gt;show();
    }
}

Widget::~Widget()
{
    delete ui;
}
</code></pre>
]]></description><link>https://forum.qt.io/topic/96075/signals-and-slots-between-two-classes</link><generator>RSS for Node</generator><lastBuildDate>Sun, 12 Apr 2026 22:58:20 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/96075.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 29 Oct 2018 15:42:43 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Signals and Slots between two classes on Tue, 30 Oct 2018 09:11:38 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mrjj">@<bdi>mrjj</bdi></a> said in <a href="/post/489819">Signals and Slots between two classes</a>:</p>
<blockquote>
<p dir="auto">Test t;<br />
QObject::connect(&amp;t, &amp;Test::ValueChanged, &amp;w, &amp;Widget::setValue);</p>
</blockquote>
<p dir="auto">Thanks. It is solved.</p>
]]></description><link>https://forum.qt.io/post/489972</link><guid isPermaLink="true">https://forum.qt.io/post/489972</guid><dc:creator><![CDATA[ktrsathish]]></dc:creator><pubDate>Tue, 30 Oct 2018 09:11:38 GMT</pubDate></item><item><title><![CDATA[Reply to Signals and Slots between two classes on Mon, 29 Oct 2018 17:33:28 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/ktrsathish">@<bdi>ktrsathish</bdi></a><br />
Hi<br />
In class Form, you have<br />
private:<br />
..<br />
Test obj;</p>
<p dir="auto">and you use that to emit</p>
<p dir="auto">void Form::on_ABS_ON_clicked()<br />
{<br />
value = 1;<br />
obj.EnableImage(value);<br />
}</p>
<p dir="auto">BUT<br />
the one you hook up in main is another test instance<br />
and its not used to emit the signal.</p>
<pre><code>Test t;
 QObject::connect(&amp;t, &amp;Test::ValueChanged, &amp;w, &amp;Widget::setValue);

t is not the one u use to emit signal.

</code></pre>
<p dir="auto">So that is why all looks fine but nothing happens.<br />
The actual emitter object is not connected up.</p>
<p dir="auto">So it was as mr. <a class="plugin-mentions-user plugin-mentions-a" href="/user/christian-ehrlicher">@<bdi>Christian-Ehrlicher</bdi></a> said / suggested</p>
]]></description><link>https://forum.qt.io/post/489819</link><guid isPermaLink="true">https://forum.qt.io/post/489819</guid><dc:creator><![CDATA[mrjj]]></dc:creator><pubDate>Mon, 29 Oct 2018 17:33:28 GMT</pubDate></item><item><title><![CDATA[Reply to Signals and Slots between two classes on Mon, 29 Oct 2018 17:15:12 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mrjj">@<bdi>mrjj</bdi></a> <a href="https://drive.google.com/file/d/1d0Cc86uItT6F-ZzpbWtreATYICApRG1U/view?usp=sharing" target="_blank" rel="noopener noreferrer nofollow ugc">https://drive.google.com/file/d/1d0Cc86uItT6F-ZzpbWtreATYICApRG1U/view?usp=sharing</a> can you try now.</p>
]]></description><link>https://forum.qt.io/post/489816</link><guid isPermaLink="true">https://forum.qt.io/post/489816</guid><dc:creator><![CDATA[ktrsathish]]></dc:creator><pubDate>Mon, 29 Oct 2018 17:15:12 GMT</pubDate></item><item><title><![CDATA[Reply to Signals and Slots between two classes on Mon, 29 Oct 2018 16:54:52 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/ktrsathish">@<bdi>ktrsathish</bdi></a><br />
super !<br />
but it asks permissions.<br />
Can you remove that ?</p>
]]></description><link>https://forum.qt.io/post/489813</link><guid isPermaLink="true">https://forum.qt.io/post/489813</guid><dc:creator><![CDATA[mrjj]]></dc:creator><pubDate>Mon, 29 Oct 2018 16:54:52 GMT</pubDate></item><item><title><![CDATA[Reply to Signals and Slots between two classes on Mon, 29 Oct 2018 16:53:51 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mrjj">@<bdi>mrjj</bdi></a> <a href="https://drive.google.com/file/d/1d0Cc86uItT6F-ZzpbWtreATYICApRG1U/view?ts=5bd73a93" target="_blank" rel="noopener noreferrer nofollow ugc">https://drive.google.com/file/d/1d0Cc86uItT6F-ZzpbWtreATYICApRG1U/view?ts=5bd73a93</a><br />
Please check the code and let me know the details.</p>
]]></description><link>https://forum.qt.io/post/489812</link><guid isPermaLink="true">https://forum.qt.io/post/489812</guid><dc:creator><![CDATA[ktrsathish]]></dc:creator><pubDate>Mon, 29 Oct 2018 16:53:51 GMT</pubDate></item><item><title><![CDATA[Reply to Signals and Slots between two classes on Mon, 29 Oct 2018 16:47:47 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/ktrsathish">@<bdi>ktrsathish</bdi></a><br />
Hi<br />
Could you zip sample and upload via<br />
<s><a href="https://www.justbeamit.com/" target="_blank" rel="noopener noreferrer nofollow ugc">https://www.justbeamit.com/</a></s> ( single use :( )<br />
any other dropbox, Google drive, etc that can give a link<br />
with no registration required to get it.</p>
<p dir="auto">Code looks ok, but its easy to miss stuff due to all the scrolling.</p>
]]></description><link>https://forum.qt.io/post/489810</link><guid isPermaLink="true">https://forum.qt.io/post/489810</guid><dc:creator><![CDATA[mrjj]]></dc:creator><pubDate>Mon, 29 Oct 2018 16:47:47 GMT</pubDate></item><item><title><![CDATA[Reply to Signals and Slots between two classes on Mon, 29 Oct 2018 16:31:06 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/christian-ehrlicher">@<bdi>Christian-Ehrlicher</bdi></a> My actual implementaion shall follow the above architecture. so I have written the sample code to work first.</p>
]]></description><link>https://forum.qt.io/post/489808</link><guid isPermaLink="true">https://forum.qt.io/post/489808</guid><dc:creator><![CDATA[ktrsathish]]></dc:creator><pubDate>Mon, 29 Oct 2018 16:31:06 GMT</pubDate></item><item><title><![CDATA[Reply to Signals and Slots between two classes on Mon, 29 Oct 2018 16:21:23 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/ktrsathish">@<bdi>ktrsathish</bdi></a> said in <a href="/post/489793">Singals and Slots between two classes</a>:</p>
<blockquote>
<p dir="auto">Form::Form(QWidget *parent) :<br />
QWidget(parent),<br />
ui(new Ui::Form)<br />
{<br />
ui-&gt;setupUi(this);<br />
value = 0;<br />
Test obj;<br />
}</p>
</blockquote>
<p dir="auto">What should 'Test obj' do here?</p>
<blockquote>
<p dir="auto">void Form::on_button_clicked()<br />
{<br />
value = 1;<br />
obj.EnableImage(value);<br />
}</p>
</blockquote>
<p dir="auto">This is not the object you're doing your connect on.</p>
]]></description><link>https://forum.qt.io/post/489806</link><guid isPermaLink="true">https://forum.qt.io/post/489806</guid><dc:creator><![CDATA[Christian Ehrlicher]]></dc:creator><pubDate>Mon, 29 Oct 2018 16:21:23 GMT</pubDate></item><item><title><![CDATA[Reply to Signals and Slots between two classes on Mon, 29 Oct 2018 16:07:48 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/vronin">@<bdi>VRonin</bdi></a>  no change. signals are not recieved in slots.</p>
]]></description><link>https://forum.qt.io/post/489803</link><guid isPermaLink="true">https://forum.qt.io/post/489803</guid><dc:creator><![CDATA[ktrsathish]]></dc:creator><pubDate>Mon, 29 Oct 2018 16:07:48 GMT</pubDate></item><item><title><![CDATA[Reply to Signals and Slots between two classes on Mon, 29 Oct 2018 15:58:48 GMT]]></title><description><![CDATA[<p dir="auto">Can you use the new connection syntax?<br />
<code>QObject::connect(&amp;t, SIGNAL(valueChanged(int)),&amp;w, SLOT(setValue(int)));</code> should become <code>QObject::connect(&amp;t,&amp;Test::valueChanged,&amp;w,&amp;Widget::setValue);</code></p>
]]></description><link>https://forum.qt.io/post/489800</link><guid isPermaLink="true">https://forum.qt.io/post/489800</guid><dc:creator><![CDATA[VRonin]]></dc:creator><pubDate>Mon, 29 Oct 2018 15:58:48 GMT</pubDate></item></channel></rss>