How to show message on resume from sleep mode
-
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?