<?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 can i log all executions of QAction?]]></title><description><![CDATA[<p dir="auto">In our application we want to log all QAction executions to a log file. All Commands are called using QAction objects, and using that we would be able to reconstruct what a user did.<br />
I originally wanted to extend QAction with a own class and just overload the triggered method, but this method is not virtual as most others of QAction.</p>
<p dir="auto">I then tried to add signals following this approach here<br />
<a href="https://stackoverflow.com/questions/70064468/list-all-signals-emitted-from-qt-application/70066122#70066122" target="_blank" rel="noopener noreferrer nofollow ugc">https://stackoverflow.com/questions/70064468/list-all-signals-emitted-from-qt-application/70066122#70066122</a></p>
<p dir="auto">But i am unable to get the calling QAction Element.<br />
Is there a way to do this without adding code to each command we implemented?</p>
]]></description><link>https://forum.qt.io/topic/139613/how-can-i-log-all-executions-of-qaction</link><generator>RSS for Node</generator><lastBuildDate>Thu, 05 Nov 2026 05:26:43 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/139613.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 27 Sep 2022 14:09:36 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to How can i log all executions of QAction? on Wed, 28 Sep 2022 10:27:48 GMT]]></title><description><![CDATA[<p dir="auto">Ah, it works that way:</p>
<pre><code>connect(this, &amp;QAction::triggered, this, &amp;MyAction::onTriggered);
</code></pre>
<p dir="auto">If do that in the constructor ill have to overload all 3 different ctors - but yes that would probably work to.</p>
]]></description><link>https://forum.qt.io/post/730470</link><guid isPermaLink="true">https://forum.qt.io/post/730470</guid><dc:creator><![CDATA[stefanwoe]]></dc:creator><pubDate>Wed, 28 Sep 2022 10:27:48 GMT</pubDate></item><item><title><![CDATA[Reply to How can i log all executions of QAction? on Wed, 28 Sep 2022 06:36:57 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jsulm">@<bdi>jsulm</bdi></a> Nothing i tried compiled, but i may have done it wrong Thats not important for me. The solution seems to work. Thats important.</p>
]]></description><link>https://forum.qt.io/post/730462</link><guid isPermaLink="true">https://forum.qt.io/post/730462</guid><dc:creator><![CDATA[stefanwoe]]></dc:creator><pubDate>Wed, 28 Sep 2022 06:36:57 GMT</pubDate></item><item><title><![CDATA[Reply to How can i log all executions of QAction? on Wed, 28 Sep 2022 05:37:07 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/stefanwoe">@<bdi>stefanwoe</bdi></a> said in <a href="/post/730447">How can i log all executions of QAction?</a>:</p>
<blockquote>
<p dir="auto">but i failed on this</p>
</blockquote>
<p dir="auto">Why? What happened and how exactly did you try?</p>
]]></description><link>https://forum.qt.io/post/730449</link><guid isPermaLink="true">https://forum.qt.io/post/730449</guid><dc:creator><![CDATA[jsulm]]></dc:creator><pubDate>Wed, 28 Sep 2022 05:37:07 GMT</pubDate></item><item><title><![CDATA[Reply to How can i log all executions of QAction? on Wed, 28 Sep 2022 05:35:15 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mchinand">@<bdi>mchinand</bdi></a> N0, i tried, but i failed on this.</p>
]]></description><link>https://forum.qt.io/post/730447</link><guid isPermaLink="true">https://forum.qt.io/post/730447</guid><dc:creator><![CDATA[stefanwoe]]></dc:creator><pubDate>Wed, 28 Sep 2022 05:35:15 GMT</pubDate></item><item><title><![CDATA[Reply to How can i log all executions of QAction? on Tue, 27 Sep 2022 21:05:20 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/stefanwoe">@<bdi>stefanwoe</bdi></a> said in <a href="/post/730411">How can i log all executions of QAction?</a>:</p>
<blockquote>
<p dir="auto">connect(this, SIGNAL(triggered(bool)), this, SLOT(onTriggered(bool)));</p>
</blockquote>
<p dir="auto">Couldn't you put this connect statement (and switch to the new(ish) connect format) in the constructor of <code>MyAction</code>?</p>
]]></description><link>https://forum.qt.io/post/730416</link><guid isPermaLink="true">https://forum.qt.io/post/730416</guid><dc:creator><![CDATA[mchinand]]></dc:creator><pubDate>Tue, 27 Sep 2022 21:05:20 GMT</pubDate></item><item><title><![CDATA[Reply to How can i log all executions of QAction? on Tue, 27 Sep 2022 20:31:42 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/derreisende">@<bdi>DerReisende</bdi></a><br />
As noted above, you cant override QAction::activate its not virtual.</p>
]]></description><link>https://forum.qt.io/post/730413</link><guid isPermaLink="true">https://forum.qt.io/post/730413</guid><dc:creator><![CDATA[stefanwoe]]></dc:creator><pubDate>Tue, 27 Sep 2022 20:31:42 GMT</pubDate></item><item><title><![CDATA[Reply to How can i log all executions of QAction? on Tue, 27 Sep 2022 20:22:58 GMT]]></title><description><![CDATA[<p dir="auto">I found a rather simple solution inspired by @DerReisende.<br />
It just uses a signal / slot. So all i had to do besides this, was<br />
replace "new QAction" by "new MyAction" all over my program.</p>
<p dir="auto">This seems to work fine:</p>
<pre><code>class MyAction : public QAction
{
    Q_OBJECT
    using QAction::QAction;

    bool event(QEvent *e);

public slots:
    void onTriggered(bool);
};

bool MyAction ::event(QEvent *e)
{
    if(e-&gt;type() == QEvent::ActionChanged)
    {
        static const QMetaMethod triggeredSignal = QMetaMethod::fromSignal(&amp;CMDIAction::triggered);

        if(! isSignalConnected(triggeredSignal))
           connect(this, SIGNAL(triggered(bool)), this, SLOT(onTriggered(bool)));
    }
    return QAction::event(e);
}

void MyAction ::onTriggered(bool)
{
    gLogStream &lt;&lt; " Action Triggered: " &lt;&lt; text() ;
}
</code></pre>
]]></description><link>https://forum.qt.io/post/730411</link><guid isPermaLink="true">https://forum.qt.io/post/730411</guid><dc:creator><![CDATA[stefanwoe]]></dc:creator><pubDate>Tue, 27 Sep 2022 20:22:58 GMT</pubDate></item><item><title><![CDATA[Reply to How can i log all executions of QAction? on Tue, 27 Sep 2022 20:10:29 GMT]]></title><description><![CDATA[<p dir="auto">I meant <code>void QAction::activate(ActionEvent event)</code>:</p>
<pre><code class="language-c++">void QAction::activate(ActionEvent event)
1113	{
1114	    Q_D(QAction);
1115	    if (event == Trigger) {
1116	        // Ignore even explicit triggers when explicitly disabled
1117	        if ((d-&gt;explicitEnabled &amp;&amp; !d-&gt;explicitEnabledValue) || (d-&gt;group &amp;&amp; !d-&gt;group-&gt;isEnabled()))
1118	            return;
1119	        QPointer&lt;QObject&gt; guard = this;
1120	        if (d-&gt;checkable) {
1121	            // the checked action of an exclusive group may not be unchecked
1122	            if (d-&gt;checked &amp;&amp; (d-&gt;group
1123	                               &amp;&amp; d-&gt;group-&gt;exclusionPolicy() == QActionGroup::ExclusionPolicy::Exclusive
1124	                               &amp;&amp; d-&gt;group-&gt;checkedAction() == this)) {
1125	                if (!guard.isNull())
1126	                    emit triggered(true);
1127	                return;
1128	            }
1129	            setChecked(!d-&gt;checked);
1130	        }
1131	        if (!guard.isNull())
1132	            emit triggered(d-&gt;checked);
1133	    } else if (event == Hover) {
1134	        emit hovered();
1135	    }
1136	}
</code></pre>
<p dir="auto">This is from Qt6 source file and maybe you should be able to properly put logging content in your override.</p>
]]></description><link>https://forum.qt.io/post/730410</link><guid isPermaLink="true">https://forum.qt.io/post/730410</guid><dc:creator><![CDATA[DerReisende]]></dc:creator><pubDate>Tue, 27 Sep 2022 20:10:29 GMT</pubDate></item><item><title><![CDATA[Reply to How can i log all executions of QAction? on Tue, 27 Sep 2022 19:45:46 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/derreisende">@<bdi>DerReisende</bdi></a> I tried that, but i dont find a matching event type:<br />
I find 3 events related to actions:<br />
QEvent::ActionAdded	<br />
QEvent::ActionChanged	<br />
QEvent::ActionRemoved<br />
(<a href="https://doc.qt.io/qt-6/qevent.html" target="_blank" rel="noopener noreferrer nofollow ugc">https://doc.qt.io/qt-6/qevent.html</a>)</p>
<p dir="auto">QEvent::ActionChanged	will be send when executing but also when building the events or on a a language change etc. I dont find a way to distinguish this.</p>
]]></description><link>https://forum.qt.io/post/730408</link><guid isPermaLink="true">https://forum.qt.io/post/730408</guid><dc:creator><![CDATA[stefanwoe]]></dc:creator><pubDate>Tue, 27 Sep 2022 19:45:46 GMT</pubDate></item><item><title><![CDATA[Reply to How can i log all executions of QAction? on Tue, 27 Sep 2022 15:28:32 GMT]]></title><description><![CDATA[<p dir="auto">Having had only a quick look at QAction source why don‘t you overrride the event() function and do the logging before emitting the appropriate signals?</p>
]]></description><link>https://forum.qt.io/post/730367</link><guid isPermaLink="true">https://forum.qt.io/post/730367</guid><dc:creator><![CDATA[DerReisende]]></dc:creator><pubDate>Tue, 27 Sep 2022 15:28:32 GMT</pubDate></item></channel></rss>