Serializing objects in XML format
The JSON serialization was a direct representation of the C++ objects and Qt already provides all we need. However, the serialization of a C++ object can be done with various representations in an XML format. So we have to write the XML â” QVariant
conversion ourselves. We have decided to use the following XML representation:
<[name]> type="[type]">[data]</[name]>
For example, the soundId
type gives this XML representation:
<soundId type="int">2</soundId>
Create a C++ class XmlSerializer
that also inherits from Serializer
. Let's begin with the save()
function, here is XmlSerializer.h
:
#include <QXmlStreamWriter> #include <QXmlStreamReader> #include "Serializer.h" class XmlSerializer : public Serializer { public: ...
Get Mastering Qt 5 now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.