Search code examples
c++macosqtqt5

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


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?


Solution

  • 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#).