Reader small image

You're reading from  Hands-On Embedded Programming with Qt

Product typeBook
Published inJul 2019
Reading LevelIntermediate
PublisherPackt
ISBN-139781789952063
Edition1st Edition
Languages
Tools
Right arrow
Author (1)
John Werner
John Werner
author image
John Werner

John Werner is an internationally published author, engineer, consultant, and conference speaker with more than 15 years' experience. He has earned patents for inventions ranging from Inkjet printers to automotive ignition systems. John was one of the early users of Qt on QNX and contributed to the early knowledge of how to make it work. He is a contributor to the Qt-related information on Stack Exchange. He is currently a senior software engineer, specializing in Qt development, for Caliber Imaging & Diagnostics.
Read more about John Werner

Right arrow

Running Your First Application on the Target

In Chapter 1, Setting Up the Environment, we worked through the process of setting up our Host for Qt development and cross-compilation, and we set up our Target. In Chapter 2, Writing Your First Qt Application, we wrote a simple Qt program. In this chapter, we will configure Qt Creator to work with the Target and run greetings from Qt on it.

In the process, we will be covering the following topics:

  • Configuring Qt Creator for our Target
  • Building for the Target
  • Deploying on the Target
  • Running the application on the Target
  • Debugging on the Target

By the end of this chapter, you should have learned the following:

  • How to configure Qt Creator for cross-compilation builds
  • How to transfer an application to the Target
  • How to run and debug the application on the Target
  • How to use layouts to make flexible displays
...

Technical requirements

Configuring Qt Creator for our Target

Back when I started cross-compiling Qt for embedded QNX devices, Qt Creator was just starting to offer limited support for handing remote Targets. Fortunately for us, a lot of work was put into Qt Creator to make it very easy to implement cross-compilation, remote running, and remote debugging.

The following sections walk you through the process of setting up Qt Creator. These same basic steps can be applied for any supported Targets. The order of the steps is important, as some steps require the previous steps to have been completed first:

  1. Tell Qt Creator about the device
  2. Tell Qt Creator about the cross-compiler toolchain
  3. Configure the debugger for the device
  4. Tell Qt Creator about the Qt build for the device
  5. Create a Qt Kit with the preceding information

Each step has its own section.

All settings are done through the Options dialog. You...

Building for the Target

Once we have configured a kit for our Qt build for the Raspberry Pi, we can start building Qt applications for the Target. You have already created one Qt application, and you have been told that it is very easy to rebuild a Qt application for different devices. Why don't we prove that? We will start by rebuilding HelloFromQt for the Target.

Open the HelloFromQt project if it is not already open.

Adding a kit to the project

The Projects page in Qt Creator allows us to configure a project, including adding a new kit to be built. You can access the Projects page by clicking the Projects icon () in the left icon bar:

Adding the Raspi kit is very straightforward:

  1. Right-click on Raspi under Build...

Deploying on the Target

Once built, HelloFromQt can be deployed on the Target by selecting Build | Deploy Project from the top menu bar. You can verify the successful deployment by looking at the Compile Output window. Click on 4 Compile Output on the bottom bar to open it.

It should look something like this:

22:54:10: Running steps for project ch03-HelloFromQt...
22:54:10: Configuration unchanged, skipping qmake step.
22:54:10: Starting: "/usr/bin/make" -j4
make: Nothing to be done for 'first'.
22:54:10: The process "/usr/bin/make" exited normally.
22:54:10: Connecting to device...
22:54:10: The remote file system has 944 megabytes of free space, going ahead.
22:54:10: Deploy step finished.
22:54:10: Trying to kill "/opt/ch03-HelloFromQt/bin/ch03-HelloFromQt" on remote device...
22:54:11: Remote application killed.
22:54:11: Deploy step finished...

Running the application on the Target

In Chapter 2, Writing Your First Qt Application, you learned how to use the Run icon () to compile and run the program, but this time, we will use a slightly different way:

  1. Open an SSH connection to the Target:
$ ssh root@raspberrypi
  1. Execute the application directly from the command line:
root@raspberrypi:~# /opt/ch03-HelloFromQt/bin/ch03-HelloFromQt
  1. Using the mouse and keyboard connected to the Target, type in your name and click Enter Name:

Once again, we find that the application doesn't display correctly. Apparently, the Target and the host use different sizes for the main window and fonts. That's okay; we can fix it.

Making a more flexible display using layouts

When...

Debugging on the Target

If you are expecting a really long and complex answer to How do I debug code running on the Target?, then you are going to be very disappointed. Qt Creator makes it incredibly easy. Are you ready?

To debug your code on the Target, simply make sure you have selected the Target build profile, then click the Debug icon () in the left toolbar.

Troubleshooting debugging

While developing this chapter, I ran into a small problem. I kept having issues with Qt Creator connecting to the debug program on the Target. After a few failed attempts, and a complete rebuild of my Target image for other reasons, I found the answer. The Yocto image we started with comes with a firewall installed. The firewall prevented...

Summary

The goal of this chapter was to run our application on the Target. Hopefully, you were able to run it successfully.

The first thing we learned was how to configure Qt Creator for cross-compilation. This process can be applied to any system where you need to do cross-compilation, not just with our Target. We then learned how to deploy (or transfer) our code to the Target.

Once we had deployed our code, we learned another way of starting the code on the Target that did not require Qt Creator. We also saw how easy it was to start debugging code on the Target.

Finally, we learned a little about Qt's layout system for GUIs. It allowed us to make the display look good both on the Host and the Target, even though they had different screen sizes.

You should now know enough to be able to run some of the examples that came with Qt 5.12.0 on the Target. Try it!

In the Chapter...

Questions

  1. What is a Qt Creator kit?
  2. Where are kits configured?
  3. How do you add a new device to Qt Creator?
  4. How can you tell where the application is deployed to on the Target?
  5. What is a layout?
  6. If you are designing a form, what kind of layout would you use?
  7. How can you space things out in a layout?
  8. How can you switch layout types for the main window?
  9. How do you switch between different configurations for a project?
  10. In Qt Creator, how do you start debugging an application on the Target?
  11. How would you configure Qt's Analog Clock Window Example to run a build for and then run on the Target?
lock icon
The rest of the chapter is locked
You have been reading a chapter from
Hands-On Embedded Programming with Qt
Published in: Jul 2019Publisher: PacktISBN-13: 9781789952063
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 $15.99/month. Cancel anytime

Author (1)

author image
John Werner

John Werner is an internationally published author, engineer, consultant, and conference speaker with more than 15 years' experience. He has earned patents for inventions ranging from Inkjet printers to automotive ignition systems. John was one of the early users of Qt on QNX and contributed to the early knowledge of how to make it work. He is a contributor to the Qt-related information on Stack Exchange. He is currently a senior software engineer, specializing in Qt development, for Caliber Imaging & Diagnostics.
Read more about John Werner