Why do you want to get the property count and name? What exactly are you trying to achieve?
Why do you want to get the property count and name? What exactly are you trying to achieve?
I have a xml. It contains the property name and value. I want to fill the structure/class and want to pass it to a function.
Basically i want to fill a class without knowing its member variable and type.
Or if You need an QObject simply use dynamic properties with methods QObject::setProperty and QObject::property. In this case, you do not need to define anything.
No, you didn't need this in this case.I think I have to use meta object to get the property count and name.
In documentation about Qt property system you can find
Qt Code:
button->setDown(true); object->setProperty("down", true);To copy to clipboard, switch view to plain text mode
http://doc.qt.io/qt-4.8/Accessing a property through its WRITE accessor is the better of the two, because it is faster and gives better diagnostics at compile time, but setting the property this way requires that you know about the class at compile time. Accessing properties by name lets you access classes you don't know about at compile time.
http://doc.qt.io/qt-5/properties.html
Thanks to all for helping me.
I think QHash will be a good option.Why not use QVariantMap instead of QObject?
This is also fine. I wll try it.Or if You need an QObject simply use dynamic properties with methods QObject::setProperty and QObject:roperty. In this case, you do not need to define anything.
Yes. I think it is the best option. But for adding/removing a field I have to change it in everywhere.Accessing a property through its WRITE accessor is the better of the two
Can you please tell me which option will be the good one ?
thanks.
It depends what you want to do. If you just need a set of key-value pairs then QVariantMap is the simplest approach. If you specifically need anything from QObject legacy (e.g. signals and slots), then you will have to use QObject.
Thanks.
One last query : Which one will perform faster for only reading and writing of values ? Any idea ?
Definitely QVariant based data structures will be faster than QObject-based ones.
Bookmarks