<?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[Unable to send variable to another form]]></title><description><![CDATA[<p dir="auto">Hi</p>
<p dir="auto">I’m still new to QT and have just started using slots and signals. I’m trying to send a variable from one form to another, and then the other way back, however I wanted to attempt to do it one way first, however I’m getting an error which no matter what I try it won’t go away. I have two forms MainWindow and Settings my code is below</p>
<p dir="auto">Mainwindow.h</p>
<pre><code>signals:
    void SendData(int speed_check_mainform);
</code></pre>
<p dir="auto">Settings.h</p>
<pre><code>private slots:
    void getData(int speed_check_mainform);
</code></pre>
<p dir="auto">Settings.cpp</p>
<pre><code>void Settings::getData(int speed_check_mainform){
    qDebug() &lt;&lt; speed_check_mainform;
}
</code></pre>
<p dir="auto">MainWindow.cpp</p>
<pre><code>connect(MainWindow,SIGNAL(SendData(int)),Settings,SLOT(getData(int)));
</code></pre>
<p dir="auto">in the MainWindow.cpp is where i am getiing the error</p>
<pre><code>expected primary-expression before ',' token
</code></pre>
<p dir="auto">I’m not sure if it is something simple or not, I have looked at many examples online and I always get the same error from the connect, I have put it in the main() however still nothing. I of course know that I need to emit when using the signal but I just can’t seem to get passed this error. if anyone could help that would be great</p>
<p dir="auto">Thank  you</p>
]]></description><link>https://forum.qt.io/topic/139333/unable-to-send-variable-to-another-form</link><generator>RSS for Node</generator><lastBuildDate>Thu, 05 Nov 2026 02:49:52 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/139333.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 15 Sep 2022 07:30:00 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Unable to send variable to another form on Thu, 15 Sep 2022 14:36:28 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jsulm">@<bdi>jsulm</bdi></a></p>
<p dir="auto">sorry about that i pasted the wrong code</p>
<pre><code>void Settings::setData(int data)
{
 printf("BLAH BLAH BLAH %d\n", data);
 ui-&gt;lineEdit-&gt;setText(QString::number(data));
}
</code></pre>
<p dir="auto">this is the code im using but has the same effect and nothing happens<br />
never mind i was just being really thick i should have done this in my MainWindow.cpp</p>
<pre><code> dlg-&gt;show();
</code></pre>
]]></description><link>https://forum.qt.io/post/728866</link><guid isPermaLink="true">https://forum.qt.io/post/728866</guid><dc:creator><![CDATA[VJ01]]></dc:creator><pubDate>Thu, 15 Sep 2022 14:36:28 GMT</pubDate></item><item><title><![CDATA[Reply to Unable to send variable to another form on Thu, 15 Sep 2022 14:22:58 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/vj01">@<bdi>VJ01</bdi></a> said in <a href="/post/728862">Unable to send variable to another form</a>:</p>
<blockquote>
<p dir="auto">however i cant seem to get the line Edit to work</p>
</blockquote>
<p dir="auto">Because setText expects a QString as you can clearly see in the documentation: <a href="https://doc.qt.io/qt-6/qlineedit.html#text-prop" target="_blank" rel="noopener noreferrer nofollow ugc">https://doc.qt.io/qt-6/qlineedit.html#text-prop</a><br />
So, convert the int to QString: <a href="https://doc.qt.io/qt-6/qstring.html#number-1" target="_blank" rel="noopener noreferrer nofollow ugc">https://doc.qt.io/qt-6/qstring.html#number-1</a></p>
]]></description><link>https://forum.qt.io/post/728863</link><guid isPermaLink="true">https://forum.qt.io/post/728863</guid><dc:creator><![CDATA[jsulm]]></dc:creator><pubDate>Thu, 15 Sep 2022 14:22:58 GMT</pubDate></item><item><title><![CDATA[Reply to Unable to send variable to another form on Thu, 15 Sep 2022 14:19:30 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jonb">@<bdi>JonB</bdi></a> hi thank you for the reply i tried to implement it a different way</p>
<p dir="auto">MainWindow.cpp</p>
<pre><code>void MainWindow::on_actionSettings_triggered()
{
 qDebug() &lt;&lt; "Settings";
 Settings *dlg = new Settings();
     connect(this, SIGNAL(sendData(int)), dlg, SLOT(setData(int)));
     emit sendData(35);
 settings.show();
}
</code></pre>
<p dir="auto">Settings.cpp</p>
<pre><code>void Settings::setData(int data)
{
 printf("BLAH BLAH BLAH %d\n", data);
ui-&gt;lineEdit-&gt;setText(data);
}
</code></pre>
<p dir="auto">my printf function does show that data is 35 however i cant seem to get the line Edit to work</p>
<p dir="auto">Thank you</p>
]]></description><link>https://forum.qt.io/post/728862</link><guid isPermaLink="true">https://forum.qt.io/post/728862</guid><dc:creator><![CDATA[VJ01]]></dc:creator><pubDate>Thu, 15 Sep 2022 14:19:30 GMT</pubDate></item><item><title><![CDATA[Reply to Unable to send variable to another form on Thu, 15 Sep 2022 09:21:59 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/vj01">@<bdi>VJ01</bdi></a> said in <a href="/post/728804">Unable to send variable to another form</a>:</p>
<blockquote>
<p dir="auto"><code>connect(MainWindow,SIGNAL(SendData(int)),Settings,SLOT(getData(int)));</code></p>
</blockquote>
<p dir="auto">At a <em>guess</em>, from your <code>Settings.cpp</code> extract <code>void Settings::getData()</code> it looks like <code>Settings</code> is a class name.  For signal/slot you must connect <em>instances</em> (presumably <code>MainWindow</code> is one?), what is your <code>Settings</code> <em>instance</em>'s variable?</p>
<p dir="auto">Next, given you have declared the <code>getData()</code> slot as <code>private</code> in <code>Settings.h</code> obviously you are not going to be able to access it on a <code>Settings</code> instance anyway, only from within <code>Settings</code> class.  If you want to <code>connect()</code> to it from the outside world/on an instance don't make it <code>private</code>, that is what <code>private</code> is there to prevent!</p>
<p dir="auto">You should not be using <code>SIGNAL</code>/<code>SLOT()</code> macros for <code>connect()</code>, they are old-style from <em>many</em> years ago.  You should be using new style, the error messages may be more helpful.</p>
]]></description><link>https://forum.qt.io/post/728813</link><guid isPermaLink="true">https://forum.qt.io/post/728813</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Thu, 15 Sep 2022 09:21:59 GMT</pubDate></item></channel></rss>