<?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[How to pass paramaters to &quot;addAction&quot;]]></title><description><![CDATA[<p dir="auto">I am lost again in C++.<br />
My function is declared as such :<br />
Run_TAB (int )<br />
and I am getting this error</p>
<p dir="auto">/media/qe/TSET_QT_LABEL/QT_PROGRAMS/JUNE  4  WORKCOPY 1/CAT/mdi/mainwindow.cpp:682: error: lvalue required as unary ‘&amp;’ operand<br />
../../../JUNE  4  WORKCOPY 1/CAT/mdi/mainwindow.cpp: In member function ‘void MainWindow::createActions()’:<br />
../../../JUNE  4  WORKCOPY 1/CAT/mdi/mainwindow.cpp:682:69: error: lvalue required as unary ‘&amp;’ operand<br />
682 |                                           this, &amp;MainWindow::Run_TAB(selection));<br />
|                                                  ~~~~~~~~~<s><s><s><s><s>^</s></s></s></s></s></p>
<p dir="auto">And it looks as Run_TAB is passed to addAction as<br />
QKey Sequence.<br />
I do not get  that at all .</p>
<p dir="auto">It woks fine when Run_TAB is declared as  (void)  - no parameters.</p>
<p dir="auto">template&lt;typename Functor&gt;<br />
QAction *addAction(const QString &amp;text, Functor functor, const QKeySequence &amp;shortcut = 0);<br />
template&lt;typename Functor&gt;<br />
QAction *addAction(const QString &amp;text, const QObject *context, Functor functor, const QKeySequence &amp;shortcut = 0);<br />
template&lt;typename Functor&gt;<br />
QAction *addAction(const QIcon &amp;icon, const QString &amp;text, Functor functor, const QKeySequence &amp;shortcut = 0);<br />
template&lt;typename Functor&gt;<br />
QAction *addAction(const QIcon &amp;icon, const QString &amp;text, const QObject *context, Functor functor, const QKeySequence &amp;shortcut = 0);<br />
#else</p>
<p dir="auto">Here is my  implementation which gives the error.</p>
<pre><code>QAction *CAT_TAB = CATMenu-&gt;addAction(tr("&amp;Bluetoooth  Development (TAB) "),
                                      this, &amp;MainWindow::Run_TAB(selection));
</code></pre>
]]></description><link>https://forum.qt.io/topic/127304/how-to-pass-paramaters-to-addaction</link><generator>RSS for Node</generator><lastBuildDate>Tue, 27 Oct 2026 07:44:58 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/127304.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 04 Jun 2021 14:20:59 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to How to pass paramaters to &quot;addAction&quot; on Mon, 07 Jun 2021 12:40:06 GMT]]></title><description><![CDATA[<p dir="auto"><code>std::bind</code> also works:</p>
<pre><code>QAction *CAT_TAB = CATMenu-&gt;addAction(tr("&amp;Bluetoooth  Development (TAB) "),
                                      this, std::bind(&amp;MainWindow::Run_TAB,this,selection));
</code></pre>
]]></description><link>https://forum.qt.io/post/663842</link><guid isPermaLink="true">https://forum.qt.io/post/663842</guid><dc:creator><![CDATA[VRonin]]></dc:creator><pubDate>Mon, 07 Jun 2021 12:40:06 GMT</pubDate></item><item><title><![CDATA[Reply to How to pass paramaters to &quot;addAction&quot; on Fri, 04 Jun 2021 15:25:28 GMT]]></title><description><![CDATA[<p dir="auto">@AnneRanch said in <a href="/post/663501">How to pass paramaters to "addAction"</a>:</p>
<blockquote>
<p dir="auto">&amp;MainWindow::Run_TAB(selection)</p>
</blockquote>
<p dir="auto">This is a "pointer to function", similar to what you will find in modern connect statement:</p>
<pre><code>connect(this, &amp;Object::foo,
    that, &amp;Object::bar)
</code></pre>
<p dir="auto">This only tells the function <em>what function</em> to call on which object. But it does not tell it what parameters to pass.</p>
<p dir="auto">And so the same rules apply: you cannot pass parameters in this call - it should be:</p>
<pre><code>QAction *CAT_TAB = CATMenu-&gt;addAction(tr("&amp;Bluetoooth  Development (TAB) "),
                                      this, &amp;MainWindow::Run_TAB);
</code></pre>
<p dir="auto">If you need to pass some concrete data, you can use a lambda:</p>
<pre><code>QAction *CAT_TAB = CATMenu-&gt;addAction(tr("&amp;Bluetoooth  Development (TAB) "),
                                      this, [=]() {
    this-&gt;Run_TAB(selection);
});
</code></pre>
]]></description><link>https://forum.qt.io/post/663517</link><guid isPermaLink="true">https://forum.qt.io/post/663517</guid><dc:creator><![CDATA[sierdzio]]></dc:creator><pubDate>Fri, 04 Jun 2021 15:25:28 GMT</pubDate></item></channel></rss>