Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. PBT_APMRESUMEAUTOMATIC not received in the nativeEventFilter in QT
Forum Updated to NodeBB v4.3 + New Features

PBT_APMRESUMEAUTOMATIC not received in the nativeEventFilter in QT

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 431 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    ShikhaMishra
    wrote on last edited by ShikhaMishra
    #1

    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?

    Christian EhrlicherC 1 Reply Last reply
    0
    • S ShikhaMishra

      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?

      Christian EhrlicherC Online
      Christian EhrlicherC Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by Christian Ehrlicher
      #2

      @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.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      S 1 Reply Last reply
      0
      • Christian EhrlicherC Christian Ehrlicher

        @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.

        S Offline
        S Offline
        ShikhaMishra
        wrote on last edited by
        #3

        @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!

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved