There is no way to determine Qt when the computer goes into sleep mode or sleep mode. But there are some platform dependent methods.
On Windows, you can listen to the WM_POWERBROADCAST message in the WindowProc handler:
LRESULT WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { if (WM_POWERBROADCAST == message && PBT_APMSUSPEND == wParam) {
On linux, you can put the following shell script in /etc/pm/sleep.d, which runs the program with arguments. You can run the program and somehow notify your main application:
#!/bin/bash case $1 in suspend)
For OS X, you can see this .
Nejat source share