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

Technical requirements

In this chapter, we will continue with the development of BigProject. This chapter assumes that you will continue developing in the same code base as you did in previous chapters.

While all of the code that's developed in this chapter may be run on the Host computer, I still strongly suggest that you have your Target so that you can see how the code runs on it.

The code we will develop throughout this chapter is available as complete code in the GitHub repository for this chapter: https://github.com/PacktPublishing/Hands-On-Embedded-Programming-with-Qt/tree/master/Chapter10.

Saving settings

Up until now, there have been many hardcoded configuration and user settings. Some of them can be set through the GUI, but others have only been changeable by editing the code and recompiling. Even the ones that can be set through the GUI always start with a hardcoded value and not with the last setting that was made. It's time we changed things so that settings are preserved between runs and so that we can make changes without rebuilding the code.

To do this, we will use the QSettings class. QSettings provides cross-platform support for saving and restoring program settings.

Searching for settings

Before we can use QSettings, it would be useful to figure out what settings we need. The first ones that...

Communicating using D-Bus

D-Bus is an interprocess communication system (IPC bus) that allows multiple processes to seamlessly communicate with each other. D-Bus is often used to allow daemons (lightweight service providers) and applications wishing to use them to communicate without knowing more than what service they need. In essence, it provides another level of abstraction. A typical setup might be to have a power monitor daemon that can notify when power is failing. Applications and other services that want to do something when power starts failing can find that daemon and use it without knowing how the daemon works. This allows the application to use different hardware as long as a power monitoring daemon is provided for it.

In the typical desktop environment, there are two D-Bus buses defined: the session and system buses. Since a bus is really just an instance of a D-Bus...

Remote GUI

We live in an age of web-connected devices, and the marketing department wants to be able to say that BigProject can be accessed from the web:

  • Req 24: The system shall be accessible through a web client.

One of the more interesting features to emerge from Qt in 5.12 is support for remote GUIs using WebGL. Using this, the GUI for an application is accessed through a WebGL-compatible web browser (in other words, Chrome, Edge, or Safari).

QML-based applications can be run through WebGL by simply instructing them to run against the WebGL display platform:

[On Target]$ your-qt-application -platform webgl:port=port#

Preparing the Target

The distribution of Yocto we are using comes with a firewall already enabled on...

Printing (PDF)

Would you believe that we have new requirements? They are as follows:

  • Req 25: BigProject shall be able to generate a report of temperature readings for the last 24 hours.
  • Req 26: The report shall be output in PDF format.

Qt to the rescue!

Qt provides printing capabilities, including the ability to output to a PDF file! We will make use of it here.

The basics

While some Qt GUI objects have special print methods that can be invoked to print on QPrinter, many don't. This is because of how Qt chose to support printing.

At the base level, Qt paints GUI objects onto paint devices. When a widget is drawn on the screen, Qt is painting it onto the screen. Printing works essentially the same way. Objects are painted...

Summary

Working through this chapter, you now have hands-on experience with using QSettings to save and restore program settings, working with D-Bus to provide interprocess communications, quickly implementing a web-based UI to our BigProject, and even creating PDF reports from BigProject.

In Chapter 11, Debugging, Logging, and Monitoring Qt Applications, we will learn more about the debugging, monitoring, and testing of Qt applications. It's going to be fun!

Questions

  1. What is the first step in using almost every Qt feature we have worked with?
  2. From what you learned in this chapter, why is QVariant one of the base Qt concepts?
  3. What does IPC stand for?
  4. How do you specify that you want to start a Qt application so that its GUI is available to a web browser?
  5. What type of Qt GUI can be displayed through a web browser?
  6. Why is outputting to PDF so easy in Qt?
  7. How do you tell the Qt tools that you want to use printing in your application?

Further reading

While we have briefly touched on many topics, it is good to know that there are other resources out there to help you to learn more about some of the specifics:

  • Qt5 C++ GUI Programming Cookbook by Lee Zhi Eng
  • Application Development with Qt Creator - Second Edition by Ray Rischpater
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