QtWidgetsApplication中的EventDispatcher的创建 -- QT 6.7

#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。 主要内容已经列在下面的图中。

posted @ 2024-09-26 12:13  MarsCactus  阅读(27)  评论(0)    收藏  举报