PBT_APMRESUMEAUTOMATIC not received in the nativeEventFilter in QT
-
Re: Do an operation when computer goes to sleep
I tried the code in the given post,
#include <QAbstractEventDispatcher> #include <QAbstractNativeEventFilter> #include <windows.h> class MyEventFilter : public QAbstractNativeEventFilter { public: virtual bool nativeEventFilter(const QByteArray& eventType, void* message, long*) Q_DECL_OVERRIDE { MSG* msg = static_cast< MSG* >( message );g->message == WM_POWERBROADCAST) { switch (msg->wParam) { case PBT_APMPOWERSTATUSCHANGE: qDebug() << ("PBT_APMPOWERSTATUSCHANGE received\n"); break; case PBT_APMRESUMEAUTOMATIC: qDebug() << ("PBT_APMRESUMEAUTOMATIC received\n"); break; case PBT_APMRESUMESUSPEND: qDebug() << ("PBT_APMRESUMESUSPEND received\n"); break; case PBT_APMSUSPEND: qDebug() << ("PBT_APMSUSPEND received\n"); break; } } return false; }};and in mainwindow constructor
QAbstractEventDispatcher::instance()->installNativeEventFilter(new MyEventFilter);but all I get is PBT_APMPOWERSTATUSCHANGE. Any Idea why?
-
Re: Do an operation when computer goes to sleep
I tried the code in the given post,
#include <QAbstractEventDispatcher> #include <QAbstractNativeEventFilter> #include <windows.h> class MyEventFilter : public QAbstractNativeEventFilter { public: virtual bool nativeEventFilter(const QByteArray& eventType, void* message, long*) Q_DECL_OVERRIDE { MSG* msg = static_cast< MSG* >( message );g->message == WM_POWERBROADCAST) { switch (msg->wParam) { case PBT_APMPOWERSTATUSCHANGE: qDebug() << ("PBT_APMPOWERSTATUSCHANGE received\n"); break; case PBT_APMRESUMEAUTOMATIC: qDebug() << ("PBT_APMRESUMEAUTOMATIC received\n"); break; case PBT_APMRESUMESUSPEND: qDebug() << ("PBT_APMRESUMESUSPEND received\n"); break; case PBT_APMSUSPEND: qDebug() << ("PBT_APMSUSPEND received\n"); break; } } return false; }};and in mainwindow constructor
QAbstractEventDispatcher::instance()->installNativeEventFilter(new MyEventFilter);but all I get is PBT_APMPOWERSTATUSCHANGE. Any Idea why?
@ShikhaMishra said in PBT_APMRESUMEAUTOMATIC not received in the nativeEventFilter in QT:
I get is PBT_APMPOWERSTATUSCHANGE. Any Idea why?
Maybe because of this?
And please format your code with the code tags so it's readable for others.
-
@ShikhaMishra said in PBT_APMRESUMEAUTOMATIC not received in the nativeEventFilter in QT:
I get is PBT_APMPOWERSTATUSCHANGE. Any Idea why?
Maybe because of this?
And please format your code with the code tags so it's readable for others.
@Christian-Ehrlicher As per the post "In Windows 10, version 1507 systems or later, if the system is resuming from sleep only to immediately enter hibernation, this event is not delivered. A WM_POWERBROADCAST message is not sent in this case." But my system is not going into Hibernation after sleep. I will try on another system and check. Thanks for the reply!