[Android] QT on Android之android-lighthouse

原创 2011年10月20日 11:11:27


Compile QtCreator

To compile QtCreator you need Qt framework, if your system doesn't ship a version >=4.7.0 you mustdownload one

Clone android-qt-creator repository

git clone git://gitorious.org/~taipan/qt-creator/android-qt-creator.git

Compile QtCreator

To compile QtCreator you need to use the usual qmake & make sequence.

cd /path/to/cloneOfandroid-qt-creator qmake -r make -j3

you have to replace 3 with the number of CPU′s your PC have + 1

If you use QtSDK you must use full path for qmake command

/opt/QtSDK/Desktop/Qt/471/gcc/bin/qmake -r

of-course you have to replace /opt/QtSDK/Desktop/Qt/471/gcc/bin/qmake with the path you've installed QtSDK.

Compile Qt framework

Requirements Clone android-lighthouse repository

git clone git://gitorious.org/~taipan/qt/android-lighthouse.git

Prepare & compile Qt

cd /path/to/cloneOfandroid-lighthouse/, use androidconfigbuild.sh to configure and compile Qt framework. Use the following command if you configure/compile Qt for the first time:

./androidconfigbuild.sh -r /where/you/install/android/ndk -q 1

Previous command will cleanup any older configuration, and then will configure & build (for debugging) Qt framework, it will take a while until everything is finished.

If you want ONLY to compile Qt (you MUST have it previously configured) you should useandroidconfigbuild.sh without -q 1 option.

./androidconfigbuild.sh -r /where/you/install/android/ndk

After Qt finish the compilation you can add it to QtCreator Qt Versions, check [Setup QtCreator] page for more informations.

To complete the job, you have to push qt libs to your device.
QtCreator can do this job for you, if you check Deploy local qt libs option (Projects->Android (run tab)->Deploy configurations->Deploy local qt libs) check the picture below.

Deploy local qt libs

androidconfigbuild.sh accepts the following parameters (you can see all options by adding -help to script parameters):

usage: ./androidconfigbuild.sh options


-help Shows this message

-r NDK root. Default "/usr/local/android-ndk-r5"

-h NDK host. Default "linux-x86"

-p NDK toolchain prefix. Default "arm-linux-androideabi"

-v NDK toolchain version. Default "4.4.3"

-a Target cpu architecture. Default "armeabi" armeabi - tune for android arm v5 armeabi-v7a - tune for android arm v7

-q Qt build options. 0 - don't configure qt (only compile) default 1 - configure qt and compile qt

-d Build type. Default "1" 1 - Compile and link Qt with debugging turned on. 0 - Compile and link Qt using release compilation flags, it also contains debugging informations.

-c Patch qt. 0 - don't patch qt (used to make the installer) 1 - patch qt (default)

-i Install path. Default "/data/data/eu.licentia.necessitas.ministro/files/qt"

Setup QtCreator

After you finish to Install QtCreator or you finish to [Compile QtCreator] you have to set it up.

  • Ant version: Please check your ant version before using Qt Creator, you should at least have ant 1.8.0. You can check with the ant -version command.
  • Java Development Kit: The optimal Java Development Kit for Necessitas is the OpenJDK. You can check with the java -version command if you have it, you can also install it if you don't have the OpenJDK with thesudo apt-get install openjdk-6-jdk command.
Configure Qt Creator

You will just need to set up the Qt in Path to the freshly installed Qt for Android Sdk, and to provide the android Sdk to use.

  • Previous step should have installed you Qt Creator for Android, you will find a shortcut on your desktop.
  • Run Qt Creator for Android and click on Tools > Options, then jump to the Qt4 tab. Just add the qmake path from the Qt For Android Sdk (/opt/necessitas/Android/<qtversion>/bin/qmake by default).
  • Give this Qt version a name (e.g. android-lighthouse-4.8.0).

Set Qt Path in Qt CreatorFigure 1. Set Qt Path for Qt Creator to Qt Sdk for Android

Set Android Sdk, Ndk & Ant Path in Qt CreatorFigure 2. Set Android Sdk, Ndk & Ant Path - With this view you can even manage the AVDs you created (AVD stands for Android Virtual Device)

  • Jump back to the Qt4 tab, select the version of Qt you added previously and build the gdb helpers, so that your debugging output will be clean and easily readable for Qt specific constructs.
  • Click Apply & Ok and you are done, you can start using the awesome Qt Sdk for Android.
  • You can now try: [How to write Qt apps for Android]
How to write Qt apps for Android

There are multiple ways to develop Qt Applications for Android, the easiest one is to use the fabulous Qt Creator For Android enabling you to deploy, run and debug Qt and your Qt application on the device.

Although if you are more used to the CLI using an advanced text editor, or if you want to use another IDE thenecessitas framework provides you scripts you can use to manage your Qt for Android projects. Both ways are explained in the subchapters.

Using Qt Creator

Qt Creator is a first class IDE for developing Qt Applications with the different tools it provides. Developing a Qt Application for Android with the Qt Creator provided in the necessitas framework lets programmers be productive and enjoy Android application development in C++.

Create a new Qt C++ Project

Create a new Qt C++ Project, this can either be a Qt Gui Project or a Qt Mobile Application (in this case you will have to remove the body of MainWindow::setOrientation generated by Qt Creator, which contains references to Qt For Symbian).

Choose the Qt Version

Once you have chosen the project name QtCreator will ask you which Qt version to use. It should propose by default those you configured: android-lighthouse-4.8.0 debug & android-lighthouse-4.8.0 release. Check them if they aren’t already selected and deselect any other Qt versions which are available.

Android version targeted

When your project is created, you are almost done, you will just need to select which android version you are targeting and how you want to deploy the Qt Libs onto the device.

The Projects View

Click on the Projects view (the icon is located on the left hand side of the QtCreator window): Qt for Android Integration adds two views here: Build & Run which appear in a small box towards the top of the main window, clicking on Build or Run swaps between the Build and Run views within the Project View.

The Run ViewPackage Configurations

Select Run view and then by selecting Details at the side of Package Configurations you can select between the ManifestApplicationPermissions and Libraries tabs.

Manifest Tab

In the Manifest tab you can select which Android target SDK you want to use. This provides the different API levels which match specific Android versions. You can find more information about API levels and how they equate to the Android version here.

Note: android-4 API level is the only one which doesn’t support multitouch, so if your application needs multitouch you have to chose a higher one.

You can choose a Package name for your application, indeed the application is launched by an automatically generated java launcher, which will be packaged with your application in an .apk (more information about the .apk: Android Application Fundamentals), and an apk has to be in a package.

Package Manifest Figure 1. You can choose the Android target SDK (Android Level API) and the other Manifest information of you Android Qt application.

Application Tab

On the Application tab you can choose an icon for your application and set the application's name.

Permissions Tab

With the Permissions tab you can pick which permissions are needed for your application, so that the people installing it, will know what it will do, and that the Android OS will give your application access to the required features.

Package Permissions Figure 2. You can easily pick one of the existing Android permissions, or add yourself new ones if you are deploying for a specific Android OS.

Libraries Tab

The Libraries tab will offer you an automatic way to determine which Qt libraries you use! Or if needed let you select manually the Qt libraries and the external libraries you think your application needs. These entries will be used by the Ministro tool to determine which Qt libraries have to be downloaded.

Libraries thumbFigure 3. This gives the Java Loader the list of required Qt Libraries and other prebundled libraries, that should get loaded with your application. It also provides to ministro the list of Qt Libraries required.

Deploy Configurations

Also on the Run view you can set the Deploy Configurations, by selecting Details at the right hand side these are the different options you can choose between:

Use devices qt libs

The Use devices qt libs option depends also on the Use local qt libs option. When Use local qt libs is unchecked your application will need the Ministro package to run. However if Use local qt libs is checked, Qt Creator will pass special parameters to the application, forcing it to use Qt libraries from the/data/local/qt path on the device.

Deploy local qt libs

The Deploy local qt libs option makes Qt Creator deploy qt libs found in the Qt SDK chosen (e.g. android-lighthouse-4.8.0). This option is useful when you hack on the Qt framework to test it.

This option automatically selects the Use local qt libs option. This option get automatically unchecked after Qt Creator pushes the Qt libs. This option can be checked every time you need to push your local Qt modifications. (In fact it has the same effect as the push_qt_libs.sh script, which can be found at the root of the Qt for Android Sdk). You do not need to check Deploy local qt libs to take advantage of the Use local qt libs option.

Install Ministro system

Install Ministro system option installs the Ministro package (actually it installs any .apk you select :) ) for you. It is useful when you try to test your application on Android Virtual Devices. You can get theMinistro .apk on the Google Market or from here.

Deploy ConfigurationFigure 4. The Deploy Configuration of the Projects Run View provides different ways to deploy Qt on the Android Virtual Devices following needs

Using CLI

This part will be added, as soon as we update the helper scripts for CLI development with Qt on Android.


You are done, you can now enjoy the development phase. :) You can build and run your application on the device. You will notice that the application output is forwarded to Qt Creator and that you can get interesting debugging information there, plus you can also set breakpoints.

Debugging Qt apps for Android


Debugging multi-thread applications on Android is possible starting with android 2.2.1 version (if you are using AVD you have to choose android 2.3 or later), for more informations please check NDK-GDB.html file located into android-ndk-folder/docs.

Replace gdb version of the Android Native Development Kit

For a seamless debugging experience you should replace the default android-ndk gdb with 7.1.x or 7.2 (download). You can simply overwrite the /pathTo/android-ndk-r5b/toolchains/arm-linux-androideabi-4.4.3/folder with one of the arm-linux-androideabi-4.4.3 folder present in the tar archive.

Change Android target Sdk

Debugging native multi threaded applications on Android (Qt applications are multi threaded) is supported only since the android-10 API level, so please choose this level or a higher one if you want to be able to debug your applications.

Choose android-10 as Android target Sdk

Figure 1. Changing Android target Sdk to one which supports native multi threaded applications debugging

Rebuild your application

Please take care that you have to rebuild the application in debug mode, if you want to be able to debug it. Click on the project source tree and rebuild everything before trying to launch in debug, it will not be done automatically.

Rebuild you application

Figure 2. Clean & Rebuild everything in debug mode





Android 下Qt打开 调用系统程序打开文件

  • v6543210
  • v6543210
  • 2014年04月30日 16:57
  • 1071

Qt For Android 引导页

Qt For Android 之引导页
  • qyvlik
  • qyvlik
  • 2016年02月14日 14:21
  • 830

qt android开发篇之如何实现在不同分辨率手机中自适应字体大小,或者像素什么的

我们知道现在手机屏幕的分辨率跟电脑的分辨率不同,或许你直接在电脑中设置的字体像素大小为20,在电脑中运行的时候看起来很正常 的字体,但是部署到手机后大家分先那些字看起来像蚂蚁一样小,这时候改怎么办呢?...
  • happyrabbit456
  • happyrabbit456
  • 2017年01月11日 16:28
  • 1133

Qt for android 在安卓上面运行app启动闪黑屏的解决方法

最近在运行app的时候,发现程序启动的时候会有闪黑屏的现象,然后才 能正常进入程序。查阅很多资料,始终不能完美解决,通过不断摸索,最近才 想出一个取巧的方法,可以完美避免启动黑屏的现象。    ...
  • CLinuxF
  • CLinuxF
  • 2017年02月16日 15:56
  • 1188

Qt Quick 图像处理实例之美图秀秀(附源码下载)

在《Qt Quick 之 QML 与 C++ 混合编程详解》一文中我们讲解了 QML 与 C++ 混合编程的方方面面的内容,这次我们通过一个图像处理应用,再来看一下 QML 与 C++ 混合编程的威力...
  • foruok
  • foruok
  • 2014年07月16日 12:25
  • 21782

解决QT5.8 for android 无法连接64位Mysql的问题

  • hsh10000000
  • hsh10000000
  • 2017年05月30日 15:16
  • 592

Android Studio调用QT for Android生成的.so库

本文介绍如何实现Android 与 QT 的结合,使Android能够调用QT的代码,避免重复造轮子最近在做AndroidStudio调用QT写的so库,在网上搜集资料,大多数都不全,而且很少有And...
  • fan_xingwang
  • fan_xingwang
  • 2017年11月07日 16:52
  • 424

Qt For Android 文件存储

Qt For Android 数据存储之文件操作
  • qyvlik
  • qyvlik
  • 2016年02月14日 14:12
  • 1707

Qt on Android 启动一个Android的服务(Service)

在一个使用Qt编写的项目中启动一个Android服务,听起来是不太现实的,实际上的确是不现实的,因此需要绕过Qt直接使用Java实现。方法如下: 生成AndroidManifast.xml文件; 使用...
  • jun4331247
  • jun4331247
  • 2016年04月18日 20:12
  • 2055

Qt5.7 for Android环境的配置

参考文章标题:基于QT 5.5.1 for Android 的 Windows 开发环境搭建 参考文章链接:http://blog.163.com/yuan_xihua/blog/static/307...
  • u013600225
  • u013600225
  • 2016年07月30日 20:14
  • 15268
您举报文章:[Android] QT on Android之android-lighthouse