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

查看:50
本文介绍了如何使用 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 应用中的任何位置调用:

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天全站免登陆