dimanche 17 septembre 2017

Qt property system: QVector. QMap

In Qt there is reflection system which we can use to read/write properties for basic datatypes.

To do it we I use this code:

int propertyStart = QObject::staticMetaObject.propertyCount();
for (int i = propertyStart; i < MyObject::staticMetaObject.propertyCount(); ++i)
{
    QMetaProperty property = MyObject::staticMetaObject.property(i);

    QVariant value = 123;  // value to write (QVector/QMap is not supported for QVariant?)

    if (QString(property.name()) == "IntegerPropertyName")
        property.write(instance, value);

}

But in my option I need to deserialize network data (such as json or binary) to my QObject with data structure defined by Q_PROPERTies in QObject (data hierarchy).

It's can be basic data types (integer, float, QString), nested data types (other QObjects) and containers (QVector, QSet and QMap, element types can be other QObjects also!)

So, I heared about Q_DECLARE_METATYPE. But I don't know how to apply this.

How to do it?





Aucun commentaire:

Enregistrer un commentaire