<?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[Odd compiler error on a signal &amp; slot]]></title><description><![CDATA[<p dir="auto">I am trying to pass some data to the main window from a child window before closing the child window, and get the following compiler errors:</p>
<p dir="auto">variable or field '<em>newDataSlot</em>' declared void   {line 27 below}</p>
<p dir="auto">'changed' was not declared in this scope           {line 27 below}</p>
<p dir="auto">The connection is defined in main</p>
<p dir="auto">@ 1 #include &lt;QtGui/QApplication&gt;<br />
2 #include "pass.h"</p>
<p dir="auto">3 int main(int argc, char *argv[])<br />
4 {<br />
5    QApplication a(argc, argv);<br />
6    pass w;<br />
7    addNew child;</p>
<p dir="auto">8    QObject::connect(&amp;child, SIGNAL(dataChangedSignal(bool)), &amp;w, SLOT(newDataSlot(bool)));</p>
<p dir="auto">9    w.show();</p>
<p dir="auto">10    return a.exec();<br />
}@</p>
<p dir="auto">I have the following definitions in pass.h</p>
<p dir="auto">@11 public:<br />
12    explicit pass(QWidget *parent = 0);<br />
13    ~pass();<br />
14    void readDataFile();<br />
15    QString name;<br />
16    QString user;<br />
17    QString date;<br />
18    QString spin;<br />
19    QString fileName;<br />
20    bool changed;</p>
<p dir="auto">21 private slots:<br />
22    void on_pushButtonQuit_clicked();<br />
23    void on_comboBox_currentIndexChanged();23<br />
24    void on_pushButtonNew_clicked();<br />
25    void on_pushButtonShow_clicked();<br />
26    void newDataSlot(bool);@</p>
<p dir="auto">newDataSlot() is defined in passKeeper as</p>
<p dir="auto">@27 void pass::newDataSlot(changed)<br />
29 {<br />
30    if (changed)<br />
31    readDataFile();<br />
32 }@</p>
<p dir="auto">In addNew.h the following signals and slots have been defined:</p>
<p dir="auto">@33 private slots:<br />
34    void on_pushButtonAdd_clicked();<br />
35    void on_pushButtonFinished_clicked();</p>
<p dir="auto">36 signals:<br />
37    void dataChangedSignal(bool);@</p>
<p dir="auto">They are then used in addNew.cpp as follows:</p>
<p dir="auto">@38 void addNew::on_pushButtonFinished_clicked()<br />
39 {<br />
40    if (addedData)<br />
41    {<br />
42        bool changed = true;<br />
43        emit dataChangedSignal(changed);<br />
44    }<br />
45        this-&gt;close();<br />
46 }@</p>
<p dir="auto">I don't understand the problem of newDataSlot being declared void.  It doesn't return any values, ad I thought that slots were required to be void.</p>
<p dir="auto">I also don't understand "changed" not being declare in scope, since it is declared in pass.h on line 20.</p>
<p dir="auto">It is quite possible that I don't fully understand the signals and slots concept or all the syntaxes involved, or is it some other dumb thing that<br />
I have missed that has the compiler confused?</p>
<p dir="auto">Can anyone help?</p>
]]></description><link>https://forum.qt.io/topic/22069/odd-compiler-error-on-a-signal-slot</link><generator>RSS for Node</generator><lastBuildDate>Sun, 19 Apr 2026 07:42:08 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/22069.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 08 Dec 2012 17:34:50 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Odd compiler error on a signal &amp; slot on Tue, 11 Dec 2012 15:19:42 GMT]]></title><description><![CDATA[<p dir="auto">Thanks for the help.</p>
<p dir="auto">The problem was in the private declaration of the slot.  I didn't have to think about it very hard after you pointed it out why it made no sense to declare it as private.</p>
<p dir="auto">BTW, I did have Q_OBJECT included, I just didn't show it in the snippets.</p>
<p dir="auto">thx again!</p>
]]></description><link>https://forum.qt.io/post/159369</link><guid isPermaLink="true">https://forum.qt.io/post/159369</guid><dc:creator><![CDATA[ngbliss]]></dc:creator><pubDate>Tue, 11 Dec 2012 15:19:42 GMT</pubDate></item><item><title><![CDATA[Reply to Odd compiler error on a signal &amp; slot on Sat, 08 Dec 2012 18:26:57 GMT]]></title><description><![CDATA[<h1>Slots do not have to be void</h1>
<h1>You lack Q_OBJECT macro in pass.h</h1>
<h1>line 27: you have not specified the variable type (should be bool changed)</h1>
<h1>the slot is declared private which may cause problems</h1>
]]></description><link>https://forum.qt.io/post/159009</link><guid isPermaLink="true">https://forum.qt.io/post/159009</guid><dc:creator><![CDATA[sierdzio]]></dc:creator><pubDate>Sat, 08 Dec 2012 18:26:57 GMT</pubDate></item></channel></rss>