QtJsonSerializer icon indicating copy to clipboard operation
QtJsonSerializer copied to clipboard

Sample: SerializationException (Unable to determine typeid of meta enum SampleObject::SuperFlags)

Open samueleforconi opened this issue 5 years ago • 1 comments

Hi, I compiled the QtJsonSerializer, and installed. Then try to run sample, the only change was to Sample.pro where I added CONFIG += c++1z If I run the Sample application from the command line I get the following output:

Serializing SampleGadget:
{
    "base": [
        42,
        13
    ],
    "rawData": {
        "someData": false
    }
}


And deserializing data back:
base: QPoint(42,13)
rawData: {
    "someData": false
}


Now the test object, with the previous gadget as child:
terminate called after throwing an instance of 'QtJsonSerializer::SerializationException'
  what():  what: Failed to serialize with error: Unable to determine typeid of meta enum SampleObject::SuperFlags
Property Trace:
	flags (Type: SuperFlags)
Annullato (core dump creato)

System is Ubuntu 16.04 with: Qt v5.14.2 g++ v7.5.0

samueleforconi avatar Jul 31 '20 09:07 samueleforconi

Register QMetaType in main.cpp

` auto obj = new SampleObject(qApp);

// Insert Next Line : Register QMetaType
qRegisterMetaType<SampleObject::SuperFlags>("SuperFlags");


obj->id = 10;
obj->title = QStringLiteral("Example");
obj->flags = (SampleObject::SuperFlag)((int)SampleObject::ValueA | (int)SampleObject::ValueB);
obj->scores = {0.0, 6.66, 47.11};
obj->secret = QStringLiteral("Very secret string, not serialized");
obj->gadget = gadget;
json = serializer.serialize(obj);
qDebug() << JSON_PRINT(json);`

bigbangsw avatar Jan 01 '21 14:01 bigbangsw