How to do it…

Let's get started and learn how to create our first mobile application using Qt 5:

  1. First of all, let's create a new project by going to File | New File or Project. Then, a window will pop up for you to choose a project template. Select Qt Quick Application - Empty and click the Choose... button as shown in the following screenshot:

  1. After that, insert the project name and select the project location. Click the Next button and it will ask you to select the minimum Qt version required for your project.
Please make sure that you select a version that exists on your computer, otherwise you won't be able to run it properly.
  1. Once you have done that, proceed by clicking the Next button.
  1. Then, Qt Creator will ask you which kit you want to use for your project. These kits are basically different compilers that you can use to compile your project for different platforms. Since we're doing an application for a mobile platform, we will enable the Android kit (or the iOS kit if you're running a Mac) in order to build and export your app to your mobile device, as shown in the following screenshot. You can also enable one of the desktop kits in order for you to test your program on the desktop beforehand. Do note that you need to configure the Android kit if you're using it for the first time, so that Qt can find the directory of the Android SDK. Click Next once you're done with it:

  1. Once the project has been created, Qt Creator will automatically open up a file from your project, called main.qml. You will see a different type of script, as shown in the following code, that is very different from your usual C/C++ projects:
import QtQuick 2.11
import QtQuick.Window 2.11

Window {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
}
  1. Build and run the project now by clicking on the green arrow button located at the bottom-left corner of your Qt Creator, as shown in the following screenshot. If you set the default kit to one of the desktop kits, an empty window will pop up once the project has been compiled:

  1. We can switch between different kits by going to the Projects interface and selecting the kit you want your project to be built with, as shown in the following screenshot. You can also manage all the kits available on your computer, or add a new kit to your project from the Projects interface:

  1. If this is your first time building and running your project, you need to create a template for the Android kit under the Build settings. Once you have clicked the Create Templates button under the Build Android APK tab, as shown in the following screenshot, Qt will generate all the files required to run your app on an Android device. If you don't plan to use Gradle in your project, disable the Copy the Gradles files to Android directory option. Otherwise, you may encounter problems when trying to compile and deploy your app to your mobile device:

  1. Once you have created the template, click on the Run button. You should now see the following window pop up, asking which device it should export to:

  1. Select the device that is currently connected to your computer and press the OK button. Wait for a while for it to build the project, and you should be able to get a blank app running on your mobile device.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset