QmlInterface

The header of our custom class features a number of additions to make properties and methods visible to the QML code:

#include <QtCore/QObject> 
#include <QMediaPlayer> 
#include <QByteArray> 
 
 
class QmlInterface : public QObject { 
    Q_OBJECT     
    Q_PROPERTY(QString durationTotal READ getDurationTotal NOTIFY durationTotalChanged) 
    Q_PROPERTY(QString durationLeft READ getDurationLeft NOTIFY durationLeftChanged) 
 

The Q_PROPERTY tag tells the qmake parser that this class contains a property (variable) that should be made visible to the QML code, with the parameters specifying the name of the variable, the methods used for reading and writing the variable (if desired), and finally the signal that is emitted whenever the property has changed. ...

Get Hands-On Embedded Programming with C++17 now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.