DisplayInfo class does not provide Q-properties nor Q_INVOKABLE member functions to access display information directly from QML.
We need to develop a new class called DisplayInformation which instance is created in C++ code and passed to QML file as a context property.
First, we need to add the following line to our .mpro file to support device API:
LIBS += -lbbdevice
In the next step, we have to define our class called DisplayInformation which will be passed to the QML file. We first define a header file (DisplayInformation.hpp) that defines our class:
class DisplayInformation: public QObject
Q_PROPERTY(int displayWidth READ getDisplayWidth WRITE setDisplayWidth NOTIFY displayWidthChanged)
Q_PROPERTY(int displayHeight READ getDisplayHeight WRITE setDisplayHeight NOTIFY displayHeightChanged)
Q_INVOKABLE int getDisplayWidth();
Q_INVOKABLE void setDisplayWidth(int);
Q_INVOKABLE int getDisplayHeight();
Q_INVOKABLE void setDisplayHeight(int);
The class is extending QObject and has two data members that are accessed via their public setter and getter functions. Those member functions are Q_INVOKABLE to be able to be called from QML. Additionally, we define Q_PROPERTY properties connected to setters, getters and signals. The last one is needed for value changes.
When the header file is done, a class has to be defined inside the DisplayInformation.cpp file: