The Order of Q_PROPERTies in QMetaObject
-
Hi,
I have a class ( for example XYZ ), which has many properties, like this:
(...) Q_OBJECT Q_PROPERTY(SomeClass1* SC1 READ getSC1 WRITE setSC1 ) Q_PROPERTY(SomeClass2* SC2 READ getSC2 WRITE setSC2 ) Q_PROPERTY(SomeClass3* SC3 READ getSC3 WRITE setSC3 ) Q_PROPERTY(SomeClass4* SC4 READ getSC4 WRITE setSC4 ) Q_PROPERTY(SomeClass5* SC5 READ getSC5 WRITE setSC5 ) (...)Now I would like to iterate over that properties, like this:
auto metaObjectXYZ = objectXYZ->metaObject(); for(int i=metaObjectXYZ->propertyOffset(); i<metaObjectXYZ->propertyCount(); i++) { auto nextValue = metaObjectXYZ->property(i).read(objectXYZ); }The order of properties in this iteration, will always be the same as in the XYZ class header, so I get: sc1Obj, sc2Obj, sc3Obj, sc4Obj, sc5Obj? Or can I get a different order like sc4Obj, sc1Obj, sc5Obj, sc3Obj, sc2Obj ?
-
Hi,
I have a class ( for example XYZ ), which has many properties, like this:
(...) Q_OBJECT Q_PROPERTY(SomeClass1* SC1 READ getSC1 WRITE setSC1 ) Q_PROPERTY(SomeClass2* SC2 READ getSC2 WRITE setSC2 ) Q_PROPERTY(SomeClass3* SC3 READ getSC3 WRITE setSC3 ) Q_PROPERTY(SomeClass4* SC4 READ getSC4 WRITE setSC4 ) Q_PROPERTY(SomeClass5* SC5 READ getSC5 WRITE setSC5 ) (...)Now I would like to iterate over that properties, like this:
auto metaObjectXYZ = objectXYZ->metaObject(); for(int i=metaObjectXYZ->propertyOffset(); i<metaObjectXYZ->propertyCount(); i++) { auto nextValue = metaObjectXYZ->property(i).read(objectXYZ); }The order of properties in this iteration, will always be the same as in the XYZ class header, so I get: sc1Obj, sc2Obj, sc3Obj, sc4Obj, sc5Obj? Or can I get a different order like sc4Obj, sc1Obj, sc5Obj, sc3Obj, sc2Obj ?
@Tomi
It's a reasonable assumption that they will be in order, but I would not depend on it.What logic do you want to build on that?
-
@Asperamanca
I get data from device -
@Asperamanca
I get data from device@Tomi
You could save property name / property value pairs