Reader small image

You're reading from  Application Development with Qt Creator - Third Edition

Product typeBook
Published inJan 2020
Reading LevelBeginner
Publisher
ISBN-139781789951752
Edition3rd Edition
Languages
Right arrow
Author (1)
Lee Zhi Eng
Lee Zhi Eng
author image
Lee Zhi Eng

Lee Zhi Eng is a self-taught programmer who worked as an artist and programmer at several game studios before becoming a part-time lecturer for 2 years at a university, teaching game development subjects related to Unity and Unreal Engine. He has not only taken part in various projects related to games, interactive apps, and virtual reality but has also participated in multiple projects that are more oriented toward software and system development. When he is not writing code, he enjoys traveling, photography, and exploring new technologies.
Read more about Lee Zhi Eng

Right arrow

Developing Mobile Applications with Qt Creator

Qt and mobile development have a long history. Qt's beginnings included early releases on Linux personal digital assistants in the late nineties and at the turn of this century. Since then, it's been ported to a number of mobile environments, including the mobile variants of Linux that Nokia shipped, such as MeeGo and Symbian. While Symbian and MeeGo came and went, Qt's acceptance of mobile platforms lives on, most recently with support for Android.

In this chapter, we will talk a little about writing mobile applications and then learn how to set up Qt Creator to write applications for Android. It's worth noting that while we will leverage everything you have learned about Qt development when developing a mobile application, we also need to understand how the environments that the mobile software runs on are different...

Technical requirements

The technical requirements for this chapter include Qt 5.12.3 arm64-v8a, Qt Creator 4.9.0, and Windows 10.

Understanding mobile software development

The key point to remember when developing software for any mobile platform, such as a cell phone or tablet, is that every resource is premium. The device is smaller, meaning the following:

  • Your user will pay less attention to your application and use it for shorter periods of time.
  • The screen is smaller, so you can display less information on the display (don't be fooled by the high dot pitch of today's displays; reading a six-point font on a four-inch display is no fun, high pixel densities or not.)
  • The processor and graphics processing unit are slower.
  • There's less RAM and less graphics memory.
  • There's less persistent storage for your application's data.
  • The network is slower, by as much as three orders of magnitude.

Let's take a look at each of these in more detail.

...

Setting up Qt Creator for Android

Android's functionality is delimited in API levels; Qt for Android supports Android level 16 and above: that's Android 4.1, a variant of Gingerbread. Fortunately, most devices in the market today are at least Marshmallow (Android 6.0), making Qt for Android a viable development platform for millions of devices.

Qt doesn't require the Java programming language to develop Android applications because it uses the Android NDK toolset, which supports C++ out of the box. You can just write your C++ or QML code as usual and don't have to worry about anything else, as Qt will handle it for you.

Without further ado, let's start downloading all the pieces required for our project.

Downloading all the pieces

...

Deploying applications to Android devices

In this section, we will learn how we can build and deploy our Qt application specifically for Android devices. Deploying to Android devices is quite different from desktop or iOS. There are some setups that we need to do before we're able to deploy the app to an Android device:

  1. Let's open up the Build Settings interface by clicking on the wrench icon that says Projects located on the left panel. Please make sure that you have selected one of the Android kits (for example, Android for arm64-v8a) before doing so:
  1. After that, you will see some additional settings available on the Build Settings interface, called Build Android APK, which is specifically for the Android platform only. You will not see these settings on other build platforms:

Let's take a look at the settings one by one:

    1. First, you will see the Android...

Setting up Qt Creator for iOS

One main difference between Android and iOS development with Qt is that you cannot build and run iOS apps on Qt Creator at all, as it is not allowed by Apple. Therefore, Qt Creator can only be used for developing the app and generating the Xcode file. Xcode is the de facto programming tool and compiler for all Apple platforms, including iOS. Once the required Xcode files have been generated by Qt Creator, you then have to do the rest on Xcode.

Let's take a look at how we can set up our Qt Creator for iOS development.

First, when you create a new project, you will see quite a variety of different kits available to you. Kits with the word clang are for macOS development, which you can also use to test your app's GUI before deploying to an iOS simulator or device. The kit with the keyword for iOS is for deploying to a physical iOS device (an...

Improving support for iOS and Android applications

Qt not only makes compiling and deploying applications to iOS and Android an easy task, but it also supports native functionalities through Java (Android) and Objective C++ (iOS) coding. In the following sections, we will study both of these.

Calling Android functions from Qt

To call an Android function from Qt, we need to follow a few steps:

  1. Create an empty Qt Quick project, which we have done countless times.
  2. Open the project file (.pro) and add the following androidextras module to the project:
QT += quick
android: QT += androidextras
CONFIG += c++11
  1. Create AndroidManifest.xml and other important Android files by clicking on the Create Template button, which we learned...

Summary

Qt for Android gives you an excellent leg up on mobile development, but it's not a panacea. If you're planning to target mobile devices, you should be sure to have a good understanding of the usage patterns for your application's users, as well as the constraints in CPU, GPU, memory, and network that a mobile application must run on.

Once we understand these, however, all of our skills with Qt Creator and Qt carry over to the mobile arena. To develop for Android, begin by installing the JDK, Android Studio, Android NDK, and then develop applications as usual: compiling for the device and running on the device frequently to iron out any unexpected problems along the way.

In our final chapter, we will learn about the bunch of odds and ends in Qt Creator and Qt in general, which will make software development much easier.

...
lock icon
The rest of the chapter is locked
You have been reading a chapter from
Application Development with Qt Creator - Third Edition
Published in: Jan 2020Publisher: ISBN-13: 9781789951752
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime

Author (1)

author image
Lee Zhi Eng

Lee Zhi Eng is a self-taught programmer who worked as an artist and programmer at several game studios before becoming a part-time lecturer for 2 years at a university, teaching game development subjects related to Unity and Unreal Engine. He has not only taken part in various projects related to games, interactive apps, and virtual reality but has also participated in multiple projects that are more oriented toward software and system development. When he is not writing code, he enjoys traveling, photography, and exploring new technologies.
Read more about Lee Zhi Eng