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

Embedded and IoT Development with Qt Creator

In the previous chapter, we learned how to create mobile applications using Qt, which makes Qt a really powerful cross-platform development suite. To go even further, Qt has started to add support for embedded devices in recent versions that allow high-performance applications to be run within small hardware with limited computing power. This includes IoT (short for Internet of Things) devices, medical equipment, automobile displays, manufacturing machines, and more. Unfortunately, Qt for embedded devices is only available if you hold a Qt commercial license.

In this chapter, we will cover the following topics:

  • Setting up an embedded Linux image
  • Building a cross-compiled Qt application
  • Configuring Qt for an embedded project
  • Writing your first embedded program
  • Deploying a Qt application to an embedded system

In this chapter, you will...

Technical requirements

The technical requirements for this chapter include Qt (commercial license) 5.13.1 Boot2Qt Emulator, Qt Creator 4.10.1, Windows 10, a GNU Toolchain, Python 2.8, WinFLASHTool, Debian for BeagleBone (or another system), and an SSH server. You also need a physical embedded device, such as the Intel NUC or Raspberry Pi, for deployment.

You can apply for a 30-day trial in order to try out the various features. You will learn how to apply for the trial license in the following section of this chapter. Note that you can still develop your Qt application for embedded devices without using the commercial license, but that will require a ton of manual work and professional know-how. Other than that, you will also need a lot of patience in order to deploy your program to the embedded system without using the automated method provided by the Qt commercial license.

...

Setting up an embedded Linux image

Embedded devices used to be custom-made individually by hardware manufacturers as the firmware had to be created specifically for the chip soldered to the device. This prevented small companies and hobby developers from designing new products without cooperating with a big manufacturer, which was pretty challenging, especially for hobbyists.

However, our technology has improved significantly in recent years, which means that the chips running our PC and mobile phones have become almost as powerful as the proprietary devices produced by the big manufacturers. This has led to most manufacturers switching sides in order to use the ARM and x86 chips and, by doing so, reduce their cost on research and development. This also allows small companies or hobby developers to easily prototype their software on low-budget embedded hardware, such as the Intel...

Building a cross-compiled Qt application

Cross-compiling is where you write code on one machine but build it for another machine that runs a different operating system or processor. For instance, you could be developing your application on Windows but build it for a Linux machine; or you could be writing the code on an x86 Linux machine but building the executable for an ARMv8 Linux device.

Cross-compilation is required in the following cases:

  • The Qt toolchain or library is not available on the target device you're running
  • The target device is really slow and not suitable for compiling the code
  • The device doesn't have any display or input method

Qt commercial makes it really easy to cross-compile and deploy your application to different types of embedded devices, so a manual way is not recommended unless the hardware is not officially supported by Qt.

...

Configuring Qt for an embedded project

As you may already know, the Qt framework comes with an enormous set of libraries that may add up to several gigabytes of storage. Even at the minimum, these libraries could take up to 15 megabytes of storage, which is overkill for a small embedded device. To fix this problem, The Qt Company has provided us with a tool for configuring our Qt package before we build the Qt framework from the source for our embedded project. We can pick and choose the features that we want and discard the features that we don't need in order to reduce the Qt library size.

The tool is called the Qt Configuration Tool or qconfig-gui.exe and is located in the C:\Qt\Tools\QtConfigGui folder, as shown here:

Press the Run Configure button to start the configuration process, which will take some time to complete. Once completed, you can open up Command Prompt...

Writing your first embedded program

In Qt, there is no difference between building an application for the desktop, mobile, or an embedded device. You can create your project, as usual, but the only difference will be the building process. Let's create a Qt Quick project by going to File | New Files or Project and selecting Qt Quick Application – Empty. Make sure that you tick the Use Virtual Keyboard option when creating your Qt Quick project.

Open up main.qml when you're done. By default, the code contains an InputPanel item, which is the virtual keyboard:

InputPanel {
id: inputPanel
z: 99
x: 0
y: window.height
width: window.width

states: State {
name: "visible"
when: inputPanel.active
PropertyChanges {
target: inputPanel
y: window.height - inputPanel.height
}
}
transitions: Transition...

Deploying a Qt application to an embedded system

Finally, we will learn how to deploy our application to an actual physical device. We will cover two methods for doing this – the automated way and the manual way. The automated way requires the Qt commercial license and this feature comes together with Qt Creator. The manual way, on the other hand, does not require a commercial license, but it is a much longer process than the former. Let's take a look at each.

Automated deployment from Qt Creator

The Qt commercial license comes with a tool called Boot to Qt Flashing Wizard, which we discussed in the Setting up an embedded Linux image section. Unlike the manual way of cross-compiling in Qt, which we discussed in...

Summary

In this chapter, we went through a long journey of learning how to empower Qt's cross-platform capability and created our first application for embedded devices. We learned how to set up an embedded Linux image and write it onto an SD card or thumb drive to run it on the device.

Then, we learned how to cross-compile a Qt project from a Windows machine and export it to the Linux device. This really is a time-saving approach as embedded devices are often not powerful enough for compiling source code, and therefore it is really handy for us to be able to compile it using a different, more powerful setup and deliver it to our production device remotely without even connecting it with a USB cable.

Other than that, we also learned how to configure the Qt framework and reduce its size so that it can fit into the embedded device. This is really important because embedded...

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