Book Image

Hands-On Embedded Programming with Qt

By : John Werner
Book Image

Hands-On Embedded Programming with Qt

By: John Werner

Overview of this book

Qt is an open source toolkit suitable for cross-platform and embedded application development. This book uses inductive teaching to help you learn how to create applications for embedded and Internet of Things (IoT) devices with Qt 5. You’ll start by learning to develop your very first application with Qt. Next, you’ll build on the first application by understanding new concepts through hands-on projects and written text. Each project will introduce new features that will help you transform your basic first project into a connected IoT application running on embedded hardware. In addition to gaining practical experience in developing an embedded Qt project, you will also gain valuable insights into best practices for Qt development and explore advanced techniques for testing, debugging, and monitoring the performance of Qt applications. The examples and projects covered throughout the book can be run both locally and on an embedded platform. By the end of this book, you will have the skills you need to use Qt 5 to confidently develop modern embedded applications.
Table of Contents (22 chapters)
Free Chapter
1
Section 1: Getting Started with Embedded Qt
5
Section 2: Working with Embedded Qt
10
Section 3: Deep Dive into Embedded Qt
14
Section 4: Advanced Techniques and Best Practices
Appendix A: BigProject Requirements

What this book covers

Chapter 1, Setting Up the Environment, covers the setup of the host and target environments we will be using for the rest of the book. It starts by specifying the host hardware we will be using for learning purposes. From there, it moves on to covering how to set up the host development environment with Qt and other tools. Cross-compiling Qt for the target environment and preparing the target operating system are also covered. Parts of this chapter can be completed without the need for the host.

Chapter 2, Writing Your First Qt Application, has been written so that you can continue learning without the target system. In this chapter, we'll write our first Qt program and execute it on the host. In the process, you will learn how to start Qt Creator; build a widgets-based Qt application; compile it for the host, run it, and even debug it; all from within the Qt Creator IDE.

Chapter 3, Running Your First Application on the Target, takes the application we wrote and ran on the host in Chapter 2, Writing Your First Qt Application, and focuses on running that application on the target. You will learn how to set up a Qt Creator kit that will allow you to simply select all the proper tools and settings to cross-compile, deploy, run, and debug on an embedded target. You will also be introduced to the problem of differing screen resolutions and sizes and how to easily solve it in Qt.

Chapter 4, Important Qt Concepts, starts laying the groundwork for the remainder of the book by exploring some of the basic, underlying concepts that are found throughout Qt. We will look at signals and slots, Qt's introspection system, the model/view architecture, and how Qt abstracts hardware and software platforms so that we can easily write code once and run it on many different systems.

Chapter 5, Managing the Overall Workflow, starts by looking at how we develop safe software systems with the highest possibility of success, both in terms of quality and time to market. From there, we start BigProject. We will work on this as we learn how to develop embedded software with Qt. As we move through the book, the mythical marketing and management teams reveal the new requirements of BigProject, just like they have done in real-world projects I have worked on. To overcome one of the first changes they make, we will learn about mocking.

Chapter 6, Exploring GUI Technologies, starts by examining the two different GUI technologies, widgets and Qt Quick/QML, which are available in Qt. As we finish up exploring the differences between them and the different ways in which they are developed, there are new requirements given to us for BigProject , leading us to learn how we can combine the two GUI technologies in a single application.

Chapter 7, Adding More Features, introduces a number of new requirements. In order to satisfy these requirements, we will learn how to interact with SQL databases using Qt, design state machines graphically in Qt Creator and have them automatically converted to C++ code, deploy a virtual keyboard, and use Qt's WebSocket support. Throughout this journey, we will be adding to BigProject. We will also look at the often overlooked world of IoT security, learning why it is important, and how we can find out more about it.

Chapter 8, Qt in the Embedded World, takes a step back and looks at Qt's place in the embedded world. We will learn how the computer and embedded markets have changed since Qt was first written. We will then examine how Qt is licensed and learn what we need to be careful of in terms of which license we develop and release our product under. We will then look at some of the commercial products Qt offers to make embedded development even easier, and even see some of the specific packages Qt has developed for targeted markets, such as medical, automotive, and safety-critical systems.

Chapter 9, Exploring the IoT with Qt, brings us to IoT. Here, we will learn how IoT and Qt fit together. After receiving yet more requirements from our mythical marketing and management teams, we will learn about accessing Web APIs from within BigProject, and how to interact using the MQTT IoT protocol. In between, we will learn about Qt's sensor support, and configure and build tools to allow the user to read the target's temperature, humidity, and pressure sensors within Qt.

Chapter 10, Using More Qt-Related Technologies, continues the theme of new requirements for BigProject and explains how we can fulfill them using Qt. In this case, we will learn how to save settings, perform inter-process communications using D-Bus, write a GUI that can be accessed from a web browser, and how to print to PDF files.

Chapter 11, Debugging, Logging, and Monitoring Qt Applications, teaches us various ways to test, debug, and monitor Qt applications. We will learn about different methods for verifying software, ranging from analysis to testing, and the tools that come with Qt Creator to help us do both of these. We will also look at using Google and the Qt Test frameworks and uncover and fix a couple of latent bugs in BigProject. We will then take a quick look at some old and new debugging tricks, and finish off learning about how we can use Qt's built-in logging system.

Chapter 12, Responsive Application Programming – Threads, dives into a fun topic—threading. In this chapter, we will learn about the different threading models that Qt supports and actually compare how they work on some sample problems. Speaking of problems, we will also look at the types of problems with which the threading models work. Finally, we learn how we can communicate between threads and safely synchronize multiple threads.

Chapter 13, Qt Best Practices, wraps up our learning. Over the course of the book, we have learned the Qt Way of doing things, and that has probably gotten you wondering, Why did they do that? To answer this question, we will look at just that question. We will then try to come up with some guidelines as to when we should be using modern C++11 (or later) features, and when we should be using the Qt approach. Finally, we will look at how to write efficient Qt code and learn about some of the powerful tools Qt Creator has incorporated into it to give you advice on how to improve the efficiency of your code.

Appendix A, BigProject Requirements, contains the requirement list for BigProject.

Appendix B, Bonus Code - Simplifying Q_PROPERTY, contains macros that will make the Q_PROPERTY coding simpler.