#include "QtWidgetsApplication1.h"
#include <QtWidgets/QApplication>
class GlobalEventFilter : public QObject
{
public:
virtual bool eventFilter(QObject* watched, QEvent* event) override
{
qDebug() << "watched : " << watched << " event : " << event->type();
return false;
}
};
int main(int argc, char *argv[])
{
**QApplication **a(argc, argv);
QtWidgetsApplication1 w;
a.installEventFilter(new GlobalEventFilter());
w.show();
return a.exec();
}
EventDispatcher的建立是在QApplication 物件構造過程中 透過 QApplicationPrivate的 init函式中建立的,最終呼叫到了 QGuiApplicationPrivate重寫的void createEventDispatcher() override函式,透過QWindowsIntegration的createEventDispatcher 返回QWindowsGuiEventDispatcher。 主要內容已經列在下面的圖中。