我正在开发一些Qt / QML应用程序,该应用程序将部署到Android OS。现在,我需要模块androidextras
,但如果我把androidextras
我的内部.pro
文件,如下所示
QT += qml quick widgets sql core bluetooth printsupport androidextras
我重新运行qmake
,出现以下错误:
项目错误:QT中的未知模块:androidextras
我还尝试打开并运行示例项目Qt Notifier,但发生相同的错误,因此我无法构建应为开箱即用的应用程序或示例。
我使用KUbuntu 15.04
与gcc version 4.9.2 (Ubuntu 4.9.2-10ubuntu13)
编译器和Desktop Qt 5.5.0 GCC 64bit
Qt的版本。如何建立这个androidextras
模组?Android arm v7
从维护工具屏幕截图中可以看到,我已经安装了套件:
我用重新编译了整个Qt clear && ./configure -opensource -confirm-license -verbose -cups -plugin-sql-mysql -android-sdk /opt/android-sdk-linux -android-ndk /opt/android-ndk-r10d && make && make install
,在QtCreator中设置了Qt版本和Qt Kit,更改了构建工具,仍然弹出相同的错误。为什么?
Extras模块旨在提供特定于某个平台的附加功能,因此仅在该平台上可用。它可能是iOS应用上的徽章数量的支持,到Windows跳转列表或者一些实用功能的支持,从一个类型转换为相应的本机平台类型(例如QPixmap
到CGImageRef
,又在苹果演员)。
There exist four extras modules - Win, Mac/iOS, X11, Android - and as long as you compile for the specific chosen platform against the specific kit, everything is fine. And it's also automatic, for desktop environment: your host machine is always your target machine.
Mobile kits are instead used to cross-compile from a certain (desktop) host machine to another (mobile) target machine. In this settings you can easily (and erroneously) compile platform specific code with the wrong kit.
Generally speaking, you should put platform specific modules/code inside conditionals to ensure that it is compiled only against the specific kit for which they are available. That's especially true for software which must be compiled both for desktop and mobile platforms or across different desktop platforms. Conditional in .pro
file could look like this:
android: QT += androidextras
mac: QT += macextras
// ...other platform specific and platform independent settings
See this answer for an android .pro
example file which includes also manifest specific settings.
The same approach should be followed in code, i.e. check the OS and conditionally compile the platform code. For instance a multi-platform implementation of a function could look like this:
if defined(Q_OS_ANDROID)
#include <QtAndroid>
#include <QAndroidJniObject>
#endif
// other code...
void YourClass::function()
{
#if defined(Q_OS_ANDROID)
// platform code
#elif defined(Q_OS_WIN)
#endif
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句