Qt:事件类型定义在哪里?

Qt : Where is the event type defined?

我正在尝试根据官方网站上提供的解释在我的 Qt 应用程序中实现一个 nativeEventFilter 来拦截 windows 消息:

https://doc.qt.io/qt-5/qabstractnativeeventfilter.html#details

但是,他们没有提到 where/how 应该定义 eventType,所提供的样本也没有显示任何提示。因此,windows_dispatcher_MSG在我的程序中显然是未定义的。

下面是一个小例子:

bool Foo::nativeEventFilter(const QByteArray & eventType, void * message, long * result)
{
    static const QByteArray windowsDispatcherMSG("windows_dispatcher_MSG");
    if (eventType != windowsDispatcherMSG)
        return false;

    const MSG * m = static_cast<MSG*>(message);
    if (m->message != WM_DEVICECHANGE)
        return false;

    /** ...do something... **/
}
  1. 将事件类型与您要处理的事件类型进行比较
  2. 将 void 指针转换为 MSG
  3. 检查消息的类型
  4. 用它做任何你需要做的事情