Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. How to show message on resume from sleep mode
Forum Updated to NodeBB v4.3 + New Features

How to show message on resume from sleep mode

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
1 Posts 1 Posters 131 Views
  • 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.
  • K Offline
    K Offline
    KejPi
    wrote on last edited by
    #1

    Hello, I would need to display message to the user after resume from sleep mode on Windows. My application is based on Qt 5.15.13, I can detect resume from sleep mode event using NativeEventFilter, I can pass this event to QML using signal but it seems that QML UI is not repaint after resuming from sleep mode. UI stays the same as before entering sleep mode and it is repaint after resizing the window. Is there a way for force update of the QML UI?

    I have created simple application showing the issue. There is a connection from event filter that simply makes Rectangle visible but nothing happens until window is resized.

    Interesting pieces of the code:

        if (eventType == "windows_generic_MSG") {
            MSG* msg = static_cast<MSG*>(message);
            if (msg->message == WM_POWERBROADCAST) {
                switch (msg->wParam) {
                    case PBT_APMPOWERSTATUSCHANGE:
                        qDebug() << ("PBT_APMPOWERSTATUSCHANGE received");
                        eventProcessed = true;
                        break;
                    case PBT_APMRESUMEAUTOMATIC:
                        qDebug() << ("PBT_APMRESUMEAUTOMATIC received");
                        eventProcessed = true;
                        break;
                    case PBT_APMRESUMESUSPEND:
                        qDebug() << ("PBT_APMRESUMESUSPEND received");
                        emit resumeFromSleepMode();
                        eventProcessed = true;
                        break;
                    case PBT_APMSUSPEND:
                        qDebug() << ("PBT_APMSUSPEND received");
                        eventProcessed = true;
                        break;
                }
            }
        }
    
        import QtQuick 2.15
        import QtQuick.Window 2.15
        import QtQml 2.15
        
        Window {
            width: 640
            height: 480
            visible: true
            title: qsTr("Hello World")
        
            Rectangle {
                id: resumeSleepInfo
                width: 200
                height: 100
                anchors.centerIn: parent
                color: "red"
                Text {
                    anchors.centerIn: parent
                    text: "Resume from sleep"
                }
                visible: false
            }
        
            Connections {
                target: eventFilter
                function onResumeFromSleepMode() {
                    console.log("onResumeFromSleepMode")
                    resumeSleepInfo.visible = true;
                }
            }
        }
        
    

    I can see all the messages in the log so the event is captured correctly and also passed to QML but nothing happens.
    Any idea?

    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