I have a Qt application that periodically performs some checks using a video camera (it takes and processes an image every second). I need Windows to be active without going into hibernation nor sleep mode as long as the application is running and to achieve it I have added the following code fragment in the main.cpp file of my application
// ... previous code omitted
// From documentation, it should inform the o.s. that the app is in use preventing it to hibernate or sleep
SetThreadExecutionState(ES_CONTINUOUS | ES_DISPLAY_REQUIRED | ES_SYSTEM_REQUIRED | ES_AWAYMODE_REQUIRED);
// Execute the main application
LoginDialog loginDialog(!appMode);
int result = loginDialog.proceed() ? application.exec() : 0;
// Restore to the previous state when the app closes
SetThreadExecutionState(ES_CONTINUOUS);
return result;
// ... previous code omitted
// From documentation, it should inform the o.s. that the app is in use preventing it to hibernate or sleep
SetThreadExecutionState(ES_CONTINUOUS | ES_DISPLAY_REQUIRED | ES_SYSTEM_REQUIRED | ES_AWAYMODE_REQUIRED);
// Execute the main application
LoginDialog loginDialog(!appMode);
int result = loginDialog.proceed() ? application.exec() : 0;
// Restore to the previous state when the app closes
SetThreadExecutionState(ES_CONTINUOUS);
return result;
To copy to clipboard, switch view to plain text mode
Unfortunately this approach is not giving the desired effects and after some time it hibernates and I don't understand why. Unfortunately I can't run the program with administrator privileges and this could be the cause but I'm not sure. I would like some help in solving my problem.
Bookmarks