如何使用Qt防止屏幕锁定ios [英] How to prevent Screen lock ios with Qt

查看:329
本文介绍了如何使用Qt防止屏幕锁定ios的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Qt for iOS中开发一个包含地图的应用程序。在使用过程中,应禁用手机的屏幕锁定。
但我找不到任何解决方法如何使用Qt阻止iOS中的屏幕锁定。

I want to develop an app in Qt for iOS that contains a map. During the use, the screen lock of the phone should be disabled. But I can't find any solution how to prevent the screen lock in iOS using Qt.

怎么办?

推荐答案

您必须使用原生iOS API。您可以直接使用Qt应用程序中的clang编译器编译ObjC ++代码。

You must use the native iOS api. You can compile ObjC++ code directly with the clang compiler in your Qt application.

所以你可以混合 .cpp .mm (ObjC ++)文件。 QtCreator和 qmake 通过 OBJECTIVE_SOURCES 关键字支持此功能。

So you can mix .cpp and .mm (ObjC++) files. QtCreator and qmake support this via the OBJECTIVE_SOURCES keyword.

yourclass.mm 实施中:

    #import <Foundation/Foundation.h>
    #import <UIKit/UIKit.h>

    void YourClass::setTimerDisabled() {
        [[UIApplication sharedApplication] setIdleTimerDisabled: YES] 
    }

yourclass.h

class YourClass
{
public:
   void setTimerDisabled()
}

现在你可以在Qt-app的任何地方打电话:

Now you can call from anywhere in your Qt-app:

YourClass yc;
yc.setTimerDisbabled();

在项目文件中( .pro ) ,如果您只想在iOS上使用此文件:

In your project file (.pro), if you only want this file on iOS:

ios {
OBJECTIVE_SOURCES += \
    yourclass.mm \
}

如果你只想在一个平台上指定代码,在源文件和头文件中使用预处理器命令,如下所示:

And if you only want specified code on a single platform, use preprocessor commands in your source and header files like this:

#if defined(Q_OS_IOS)
   // iOs stuff
#elsif defined(Q_OS_ANDROID)
   //Android stuff ...
#else
  //Other stuff ...
#endif

这篇关于如何使用Qt防止屏幕锁定ios的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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