<?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 hook system events with QAbstractEventDispatcher]]></title><description><![CDATA[<p dir="auto">These are  found in document<br />
EventFilter QAbstractEventDispatcher::setEventFilter ( EventFilter filter ):<br />
Replaces the event filter function for this QAbstractEventDispatcher with filter and returns the replaced event filter function.</p>
<p dir="auto">The event filter function set here is called for all messages taken from the system event loop before the event is dispatched to the respective target, including the messages not meant for Qt objects.</p>
<p dir="auto">The event filter function should return true if the message should be filtered, (i.e. stopped). It should return false to allow processing the message to continue.</p>
<p dir="auto">Is that mean we can catch all system events very easy?<br />
Then i tested it on windows.</p>
<p dir="auto">@#include &lt;QAbstractEventDispatcher&gt;<br />
#include &lt;qt_windows.h&gt;</p>
<p dir="auto">class SysEvent : public QObject<br />
{<br />
Q_OBJECT<br />
public:<br />
explicit SysEvent(QObject *parent = 0);<br />
~SysEvent();</p>
<p dir="auto">protected:<br />
static bool sysEventFilter(void* message);<br />
static QAbstractEventDispatcher::EventFilter prevEventFilter;<br />
};</p>
<p dir="auto">SysEvent::SysEvent(QObject <em>parent) :<br />
QObject(parent)<br />
{<br />
prevEventFilter = QAbstractEventDispatcher::instance()-&gt;setEventFilter(SysEvent::sysEventFilter);<br />
}<br />
bool SysEvent::sysEventFilter(void</em> message)<br />
{<br />
qDebug("Event!");<br />
MSG* msg = static_cast&lt;MSG*&gt;(message);<br />
if (msg-&gt;message == WM_HOTKEY)<br />
{<br />
const quint32 keycode = HIWORD(msg-&gt;lParam);<br />
const quint32 modifiers = LOWORD(msg-&gt;lParam);<br />
qDebug("%d, %d", keycode, modifiers);<br />
return true;<br />
}<br />
return false;<br />
}<br />
@<br />
but when i run it, sysEventFilter() was called less then 10 times. I think other system event can call sysEventFilter() too. Am i wrong? What is the right way to catch system events with QAbstractEventDispatcher?</p>
]]></description><link>https://forum.qt.io/topic/12065/how-to-hook-system-events-with-qabstracteventdispatcher</link><generator>RSS for Node</generator><lastBuildDate>Tue, 07 Apr 2026 14:47:48 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/12065.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 09 Dec 2011 15:11:46 GMT</pubDate><ttl>60</ttl></channel></rss>