Time for action – self-updating car dashboard
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 final result will look similar to the following image:
We will start with the C++ part. Set up a new Qt Quick Application. Choose the most recent Qt Quick version for the Qt Quick component set. This will generate a 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 C++ class. Call it CarInfo
and choose QWidget
as its base class. Why not QObject
, you may ask? This is because our class will also be a widget, which will be used for modifying values of different parameters so that we may observe how they influence what the Qt Quick scene displays. In the class header, declare the following properties:
Q_PROPERTY(int rpm...