This is an article in the series. Before reading this article, read Qt 5.2 for Android development in Windows to ensure that the development environment is consistent with the author.
Part of the article was forwarded/reproduced but did not indicate the source, hereby declare: Copyright All foruok, If You Need To reprint please indicate the source (http://blog.csdn.net/foruok ).
I will start from practice and take you step by step to complete the first Qt application on Android: Hello Qt on Android. The application itself is very simple (only a string "Hello Qt on Android" is displayed on the screen), which is also common to the Hello World Program in the Getting Started tutorial of each programming language.
Next, I will explore the entire process of using Qt Creator 3.0 to create, manage, compile, and deploy the Qt on Android Application. Each step is carefully selected and organized by me, so that beginners can follow the steps to complete their first sightseeing trip on the Android platform.
Create a project
Open Qt Creator, click the file (F) menu, and select "new file or project (N)" in the pop-up menu list )". As shown in:
After the preceding operations, the new project page will pop up with Qt Creator. Let's select a project template. As shown in the following figure:
Here we select "Application" project, "Qt Widgets Application" template. You can see the real-time prompt on the rightmost side. The supported platforms include Android (shown in the Blue Line). This shows that the preceding development environment is set up correctly.
Click "select (C)...". The new Project Wizard guides us to the next step "Project Introduction and location ". Refer:
You can enter the project name in the text box marked with 1. Here is "HelloQtAndroid"; "Browse... the "button allows you to select the Project Storage path. I am going to put the project under the" D: \ projects \ blogs \ qt "directory. Check your configuration accordingly:
Click "Next" and follow the Wizard to go to the "Kit Selection" step.
I have selected two kits: "Android for armeabi (GCC 4.7, Qt 5.2.0)" and "Desktop Qt 5.2.0 MinGW 32bit", which correspond to the areas marked with 1 and 2 respectively. Check your configuration.
Click "Next" and follow the Wizard to enter the "class information" configuration step. Is the default Interface:
In the drop-down box with the value of 1, you can select the base class of the Widget to be created. The default value is QMainWindow. Here I select QWidget. The check box marked as 2. If it is selected,. ui file, you can use the interface designer in the Qt SDK to edit the interface. In order to be simple and direct, we removed the selected file and did not use it. ui file, all use code to build the interface.
Please refer to check your Configuration:
Click "Next" and follow the Wizard to go to the "Project Management" step. Here you can choose whether to add the project to the version control system (such as svn), and you can see the files to be added to our "Hello Qt on Android" project. As shown in:
Finally, the "finish (F)" button is displayed. Click it! Look, we will enter the interface with the highest frequency of use and the longest time of dependency when using Qt Creator in the near-perfect IDE programming in the future.
As shown in, this is the interface we will face every day and constantly deal. I will select several of the most common functions to briefly introduce their usage.
In the left sidebar, the label marked with 1 is the "edit" label. If you select it, the edit mode is displayed, which is shown above.
The label marked as 2 is the "project" label. If you select it, the project option configuration page is displayed. The UI features are rich and complicated. We will spend more time introducing the required options for our "Hello Qt on Android" project.
3 is the "build version" button. Click it to bring up a shortcut interface that allows us to quickly select different build versions (such as Android Release build, desktop debugging and so on ). Click the "project" tab to go to the configuration page and select the build version.
The "run" button is marked as 4. After you click it, Qt Creator will compile, Link, package, and so on until the target program starts running or stops running with an error.
The "run" button is followed by the "start debugging" and "build project" buttons, and you can see the prompt by hovering over them. Its purpose is self-evident.
The horizontal label marked as 5 is the output window of Qt Creator. clicking any label will display the information corresponding to the label name.
The build problem is displayed in the window corresponding to the problem tag. Double-click the problem to jump to the corresponding code line or compile the output window (some links are incorrect ).
The window corresponding to the compilation output tag will display the information during compilation, linking, packaging, and deployment. This is an excellent way to observe the working process of Qt Creator from the outside, good use will certainly benefit a lot.
The window corresponding to the application output tag will display the printed information of the application using the standard output. After the APK is run, the logcat log will also be displayed here.
Other labels are not described in detail, and you will be familiar with them several times during the development process.
The area marked as 6 is the code editing area.
The area marked as 7 is a sidebar and a project management area. This area allows developers to manage projects by project, Class View, outline, file system, type hierarchy, and document opening.
Project Options
After introducing our partners-project management and code editing interface, we will continue to complete the "Hello Qt on Android" project configuration. Click the project label marked as 2 in the previous section. The following project option configuration page is displayed:
For our new project, the suite "Desktop Qt 5.2.0 MinGW 32bit" is selected by default. Pay attention to the button marked in the Blue Line at the bottom left. As mentioned above, it is the build version selection button, and now displays the Debug standard for the computer diagram.
Click the build button in the area marked as 1 (where the Blue Circle is located), switch to the "Android for armeabi" suite, and configure the building. For example:
There are many options for building configuration. For our first application, you only need to pay attention to how to use the 1 and 2 features identified on the way.
Click the "1" button to switch to the "run" option configuration.
For a combo box labeled 2, you can select build version (usually Debug/Release ). It is the same as the build Version button marked by the blue circle on the Left bar. Here we select "Release" build.
Note that the Blue Circle marks the area. As we select "Android for armeabi" and "Release", it changes from the computer icon to the Android robot with the "Release" button.
Now, let's click the "run" button marked as 1 to configure the running options. For the current project, the running configuration is far more complex than the construction configuration. Please keep your eyes open and feel it with your heart.
Switch to the running configuration interface, as shown in. First, let's take a look at the deployment configuration. Click the "details" button marked as 1 in the figure to open the deployment configuration details page:
I hope you are not scared. I have made nine identifiers, more than the previous editing interface (seven identifiers. Let's turn complexity into simplicity, one by one.
In the drop-down box marked as 1, you can select the target SDK version for the application. The default value is android-17. I have to say (first, please forgive me for BogDan Vatra) that Qt Creator is not perfectly displayed. If you hover your mouse over the drop-down box, it will be better to see a floating window prompt.
Here I will briefly describe the configuration option in Qt Creator. In fact, it corresponds to the Android: targetSdkVersion configuration item in the main configuration file AndroidManifest. xml of android APK. This configuration item allows you to specify the Android API Level for your application. However, it uses sdkVersion as the tag, which may cause confusion. In fact, now we can simply think of sdkVersion and API Level as the same thing. The nuances will be discussed later.
In order to let everyone have a concept of Android API Level, I captured a picture in the Google Android online manual (please visit the page "http://developer.android.com/guide/topics/manifest/uses-sdk-element.html") Put below:
The "sign package" check box marked as 2. When selected, Qt Creator automatically signs the APK. Once you select it, you need to provide a key file (keystore) for Qt Creator to use. If no, click the "Create" button marked as 3. Qt Creator will help you Create one. If yes, click "Browse.
The single kernel marked as 4 is one of the Qt library deployment policies, and Qt is installed using the Ministro service. We recommend that you use this method. The detailed reasons are described in the "Qt library deployment policy" section. Another available policy is to package the Qt library into your APK.
The check box marked as 5. When selected, Qt Creator opens the directory where the package is packaged to facilitate developers to access the generated APK.
The log output option is selected when the label is 6.
"Create AndroidManifest. xml", as shown in the button name, helps you Create and configure the main configuration file AndroidManifest. xml of the APK. If you do not click this button, Qt Creator will use the default options to help you create a default configuration file. We recommend that you create and configure it. Otherwise, your APK package name may make you feel a little uncomfortable.
The "Install Ministro from APK" button marked as 8 is a considerate service provided by Qt Creator. It allows us to download the local Ministro APK to Android devices. By the way, when I completed the "Hello Qt on Android" project, I encountered a problem where I could not install the Ministro service. My XT882 Telecom customized mobile phone did not access Google Play.
There are two buttons in the area marked as 9, allowing us to add dependent libraries. The current project cannot be used. I will discuss it later.
Ah, God, it's over. You're asleep. Wake up. Let's continue watching.
Create a key file and Certificate
Let's go back to the Signature Option (do not forget to mark 2), select it, and click the "Create" button marked 3 to Create the key file and certificate. You will see the following interface (blank as well, yes, it is the initial interface ):
As shown in, there are many options, just fill in the line, there will be a prompt when the error. After configuration, I cut the figure. In the following, check your configuration with reference:
Click "save". The file selection dialog box is displayed, allowing you to select the location where the key file is saved. You can also modify its name. The following is my configuration for your reference:
Click --, oh, and so on. Remember the file name and saved location you just created (the same signature must be used for updating the APK in the market as the previous version ), we will use it later, and then click "save" to return to the running configuration page. As shown in:
In contrast to the initial running configuration, I marked the modified options with a blue horizontal line.
<喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD48aDE + release/L/KOsyrnTw8SsyM/WtaOouaSzzMS/release + vNCjrLvYzbfE47/release + release = "http://www.2cto.com/uploadfile/Collfiles/20140414/20140414085854216.jpg" alt = "\"/>
Click the "finish (F)" button to edit the AndroidManifest provided by Qt Creator. graphical interface of the xml file (you can also view the XML file in Qt Creator and modify it manually ). Figure:
This is a moderately complex interface. I have made six identifiers, which are described below.
Enter the package name in the "1" edit box. As you can see, the default value is org. qtproject. example, which looks less formal.
The fine-tune button marked as 2 allows you to change the application version number.
When the number is 3, the minimum API Level and target API Level are adjusted.
The area marked as 4 allows you to set your APK icon in three dimensions: High, Medium, and low (usually 72x72, 48x48, and 32x32 ).
The drop-down box with a label of 5 lists all supported permissions. You can select the required permissions for your APK, click the "Add" button marked as 6 to go to AndroidManifest. add a permission in xml. You can also click "Remove" to make fun of unnecessary permissions.
For more information about APK permissions, see "AndroidManifest. xml Introduction. For HelloQtOnAndroid, I keep the default permissions set by Qt Creator.
The following is my configuration. The modified part is marked with the blue line. Check your configuration as follows:
The graphical Android Manifest editing interface provided by Qt Creator only supports several main options. If you want to adjust the overall experience, click the "XML Source" button in the blue box, manually edit the xml file. As shown in:
Like editing C ++ code, you can edit XML files in the editing area marked as 1.
Thank God, we have been walking for 90 miles, and we will continue to be scared and pleasantly surprised.
Add code
Although you are ready for the surprise, we have to press the button to slightly modify the code. Return to the editing page, make sure that you select "project" in the Project Management window on the left, expand the source folder, double-click widget. cpp, and add a line of code in the editing area on the right:
new QLabel("Hello Qt on Android !", this);
The header file QLabel is also included.
Okay, see the figure:
Run the program
Okay, it's miles away. Please click the "run" button on the Left bar (Do you still remember ), qt Creator will let you select the target device (if the environment is correctly configured, connect to the mobile phone or create an AVD). We recommend that you run it directly on a real machine (Do You Have No Android phone ?), As shown in:
Have you seen it? Select My old antique mobile phone, Motorola XT882, Android version 2.3.6, click "OK", and wait for a while.
Oh, I was shocked. I saw this interface:
Forgot, we checked the "Open package location after build" option in the running configuration. If you want to publish your application in the market, select the version you have signed (as shown in the blue box in the figure.
Wait. Now you should check your phone. I can see this interface:
Do you still remember the selected Qt library deployment policy-"using the Ministro service to install Qt library "?
Click "OK" to install the Ministro service. Stunned, I saw a Toast flash on the screen of my mobile phone, prompting "installation of Ministro failed", and then the figure below:
It looks like it's on my mobile phone, but I can't find Ministro in the default anzhi market. Press the return key. Oh, day, it stops on the black screen, and there is no response ...... Okay. Please press the return key or home page key of your mobile phone. Oh, thanks for the desktop. For more information about why the installation of Ministro fails, see the following sections.
Now we need to go back and adjust the running configuration, and change the Qt library deployment policy-"bind the Qt library in the APK ".
Run again and you will see the "package location" folder interface ......, Okay, watching the phone, the surprise is finally coming:
Now, we can finally stop and breathe. Our first Qt on Android app "HelloQtOnAndroid" finally ran on the real machine.
If you are using Qt on Android for the first time, what does it feel like following my guide? The first time I ran "Hello Qt On Android", I was very excited and excited for a long time. After all, Qt is the only cross-platform application development framework that can be integrated with Android and iOS in the mobile Internet era ......; After all, as C/C ++ programmers, we can develop software for Windows desktop, Linux desktop, Android Mobile phone/tablet, iOS, mac OS X, Tizen, Meego, Windows Mobile, Embedded Linux, Symbian, and other platforms without switching development. frameworks and tools, what a pleasant and proud thing. After all ......
Well, this is the first journey of the Qt on Android app. We are looking forward to subsequent articles.
Hereby Declare: All Rights Reserved foruok, If You Need To reprint please note the source (http://blog.csdn.net/foruok ).
I have translated the Qt on Android series articles from BogDan Vatra: