Hi!
If found out from this example http://qtwiki.org/Parsing_JSON_with_...ard_QT_library how easy it was to parse json with Qt. Nice! But what if I need the other way around? I need to build json from QObject instance, how to do that?
Thanks!
Hi!
If found out from this example http://qtwiki.org/Parsing_JSON_with_...ard_QT_library how easy it was to parse json with Qt. Nice! But what if I need the other way around? I need to build json from QObject instance, how to do that?
Thanks!
Anyone now how to do this?
Iterate over properties of QObject and compose the json string based on the property name and property value converted to string (for scalar values) or lists or maps (for lists and maps).
EDIT: Wysota got there before me.
Thanks for the answer! I'm quite a newbie, do you have some example code that I can take a look at, it would be very very helpful! Thanks again!
Use QMetaObject associated with your object to query for names of static properties or use QObject::dynamicPropertyNames() for dynamic properties. Then query the object for value of each of the properties and compose a string using the json format.
Bookmarks