Using C++ classes as QML components
In the next exercise, we will implement a car dashboard that can be used in a racing game and will show a number of parameters such as current speed and motor revolutions per minute. The input data will be provided by a C++ object. We'll see how to include this object into the QML object tree and use property bindings to implement the dashboard.
The final result will look similar to the following:

Time for action – Self-updating car dashboard
We will start with the C++ part. Set up a new Qt Quick application. This will generate the main function for you that instantiates QGuiApplication
and QQmlApplicationEngine
and sets them up to load a QML document.
Use the File
menu to create New file or Project
and create a new Qt Designer form class. Call it CarInfo
and choose the Widget
template. We will use this class for modifying values of different parameters so that we may observe how they influence what the Qt Quick scene displays. In the class declaration,...