<?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[Passing Parameters to Slots]]></title><description><![CDATA[<p dir="auto">A slot seems to work as expected without a parameter passed to it as follows:</p>
<p dir="auto">@    connect (ui-&gt;pushButton, SIGNAL (clicked()), this, SLOT(goal_seek()));</p>
<p dir="auto">//...code...</p>
<p dir="auto">void MainWindow::goal_seek()<br />
{<br />
double seek = 5;<br />
QTableWidgetItem *itab7= new QTableWidgetItem;<br />
QString A2 = QString::number(seek);<br />
itab7-&gt;setText(A2);<br />
ui-&gt;tableWidget_2-&gt;setItem(0,7, itab7);<br />
}<br />
@</p>
<p dir="auto">However, when I use the same code, the slot does not work with the parameter passed to it, as shown below:</p>
<p dir="auto">@<br />
connect (ui-&gt;pushButton, SIGNAL (clicked()), this, SLOT(goal_seek(5.0)));</p>
<p dir="auto">void MainWindow::goal_seek(double seek)<br />
{<br />
double seek = 5;<br />
QTableWidgetItem *itab7= new QTableWidgetItem;<br />
QString A2 = QString::number(seek);<br />
itab7-&gt;setText(A2);<br />
ui-&gt;tableWidget_2-&gt;setItem(0,7, itab7);<br />
}<br />
@</p>
<p dir="auto">Can one use parameters for slots, and if so, how?</p>
]]></description><link>https://forum.qt.io/topic/37976/passing-parameters-to-slots</link><generator>RSS for Node</generator><lastBuildDate>Sat, 05 Sep 2026 14:06:27 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/37976.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 18 Feb 2014 11:41:36 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Passing Parameters to Slots on Tue, 18 Feb 2014 13:53:18 GMT]]></title><description><![CDATA[<p dir="auto">One of solutions is:<br />
@ connect (ui-&gt;pushButton, SIGNAL (clicked()), this, SLOT(some_slot()));<br />
//code...<br />
void MainWindow::some_slot()<br />
{<br />
goal_seek(5);<br />
}<br />
@<br />
or<br />
@<br />
connect (ui-&gt;pushButton, SIGNAL (clicked()), this, SLOT(some_slot()));<br />
connect (ui-&gt;pushButton, SIGNAL (clicked(int)), this, SLOT(goal_seek(int)));<br />
//code...</p>
<p dir="auto">void MainWindow::some_slot()<br />
{<br />
emit clicked(5);<br />
}<br />
@<br />
it depends from your code structure.</p>
]]></description><link>https://forum.qt.io/post/215306</link><guid isPermaLink="true">https://forum.qt.io/post/215306</guid><dc:creator><![CDATA[qxoz]]></dc:creator><pubDate>Tue, 18 Feb 2014 13:53:18 GMT</pubDate></item><item><title><![CDATA[Reply to Passing Parameters to Slots on Tue, 18 Feb 2014 12:13:52 GMT]]></title><description><![CDATA[<p dir="auto">It doesn't work. Where does the emit code go?</p>
]]></description><link>https://forum.qt.io/post/215297</link><guid isPermaLink="true">https://forum.qt.io/post/215297</guid><dc:creator><![CDATA[[[global:former-user]]]]></dc:creator><pubDate>Tue, 18 Feb 2014 12:13:52 GMT</pubDate></item><item><title><![CDATA[Reply to Passing Parameters to Slots on Tue, 18 Feb 2014 12:00:06 GMT]]></title><description><![CDATA[<p dir="auto">You are doing it wrong. You can't pass static values to slots in the connect assignment. You need to emit a value together with your signal:<br />
@<br />
// header<br />
signals:<br />
void clicked(int) const;</p>
<p dir="auto">// source<br />
connect (usomeObject, SIGNAL (clicked(int)), this, SLOT(goal_seek(int)));</p>
<p dir="auto">// signal emission:<br />
emit clicked(5);<br />
@</p>
]]></description><link>https://forum.qt.io/post/215294</link><guid isPermaLink="true">https://forum.qt.io/post/215294</guid><dc:creator><![CDATA[sierdzio]]></dc:creator><pubDate>Tue, 18 Feb 2014 12:00:06 GMT</pubDate></item></channel></rss>