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: XmlSerializer(); void save(const Serializable& serializable, const QString& filepath, const...