有没有办法在Qt禁止电脑睡觉? [英] Is there a way in Qt to prohibit the computer from going to sleep?

查看:110
本文介绍了有没有办法在Qt禁止电脑睡觉?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一个Qt应用程序,做一些沉重的计算,但在Mac(可能也在Windows上,但我目前没有办法检查这一点),一旦计算机进入睡眠模式,执行停止。

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?

推荐答案

在彻底搜索Qt 5.2 API后, t提供任何功能来改变能量设置(所以既不是Mac,也不是任何其他操作系统)。我还没有找到任何迹象表明它在他们的路线图上。

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.

可以找到一个可能的解决方案Mac OSX使用苹果的Objective-C API,在这里(感谢@Kuba)。

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

在Windows上,可以使用SetThreadExecutionState函数处理电源设置(请参阅这个问题,C#)。

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

这篇关于有没有办法在Qt禁止电脑睡觉?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆