user2556487894
user2556487894

Reputation: 33

Qt : Where is the event type defined?

I'm trying to implement a nativeEventFilter to intercept windows messages in my Qt application according to the explanations provided on the official website :

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

However, they don't mention where/how the eventType should be defined, nor the samples provided show any hints. Therefore, windows_dispatcher_MSG is obviously undefined in my program.

Upvotes: 0

Views: 456

Answers (1)

Robert
Robert

Reputation: 1343

Following a small example:

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. compare the eventType with the one you want to handle
  2. cast the void-pointer to MSG
  3. check the type of the message
  4. do whatever you need to do with it

Upvotes: 1

Related Questions