Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way in Qt to prohibit the computer from going to sleep?

Tags:

c++

macos

qt

qt5

I am writing a Qt application that does some heavy computations, but on a Mac (potentially also on Windows but I currently have no way of checking this), the execution ceases as soon as the computer goes into sleeping mode.

I would like a way to continue the execution even when the screen goes to screensaver or on blank. Obviously you can ask the user to change his/her energy settings, but that's far from an ideal solution. Is there a proper way of doing this?

like image 969
Yellow Avatar asked May 13 '14 21:05

Yellow


1 Answers

After a thorough search through the Qt 5.2 API, it seems that Qt doesn't offer any functionality to change the energy settings (so neither for Mac, nor any other operating system). I haven't found any indication that it's on their road map either.

A possible solution for Mac OSX using Apple's Objective-C API can be found here (thanks, @Kuba).

On Windows, power settings can be dealt with using the SetThreadExecutionState function (see this question, C#).

like image 57
Yellow Avatar answered Oct 10 '22 04:10

Yellow