PDA

View Full Version : QML - How to iterate through the types/properties available in a namespace



schall_l
29th July 2014, 07:50
I am using qmlRegisterUncreatableType() to register several C++ classes as QML types into a unique namespace. Each class comes with several properties.


class Battery : public QObject
{
Q_OBJECT
Q_PROPERTY(QString voltageStr READ voltageStr NOTIFY changed)
Q_PROPERTY(QString currentStr READ currentStr NOTIFY changed)
public:
// ...
};

class Load : public QObject
{
Q_OBJECT
Q_PROPERTY(QString voltageStr READ voltageStr NOTIFY changed)
Q_PROPERTY(QString currentStr READ currentStr NOTIFY changed)
Q_PROPERTY(QString activePowerStr READ activePowerStr NOTIFY changed)
Q_PROPERTY(QString reactivePowerStr READ reactivePowerStr NOTIFY changed)
public:
// ...
};

...

qmlRegisterUncreatableType<Battery>("MyDevice", 1,0, "Battery", "");
qmlRegisterUncreatableType<Battery>("MyDevice", 1,0, "Load", "");

On the QML side I would like to iterate through the types available in the MyDevice namespace and iterate through the properties made available in each class to display them for example in a tree view. The content of the TreeView should adapt automatically depending on how the amount of registered classes and properties in each class.

Has someone an idea how to iterate through the types available in a namespace and through the properties in a type available in a namespace in QML?

The result should be something like:



+ MyDevice + Battery + Voltage + Value
+ Current + Value
+ Load + Voltage + Value
+ Current + Value
+ ActivePower + Value
+ ReactivePower + Value

anda_skoa
29th July 2014, 09:33
Make a model in C++ that exposes that data.

Cheers,
_