PDA

View Full Version : Serialize class objects to XML file and back



StarShaper
22nd June 2012, 06:28
Hi,

I have two classes:


class A
{
public:
int m_x;
string m_s;
};

class B
{
public:
A m_a;
};

Now I would like to create a XML structure, like this one:


<B>
<A>
<x>12</x>
<y>55</y>
</A>
</B>

What is the best way to achieve this with Qt?

It would be necessary to read the XML and convert it to the object model later. :)

Santosh Reddy
25th June 2012, 07:42
Add an serializer operator in each class.

amleto
25th June 2012, 08:27
Hi,

I have two classes:


class A
{
public:
int m_x;
string m_s;
};

class B
{
public:
A m_a;
};

Now I would like to create a XML structure, like this one:


<B>
<A>
<x>12</x>
<y>55</y>
</A>
</B>

What is the best way to achieve this with Qt?

It would be necessary to read the XML and convert it to the object model later. :)

How do you handle this:



class A
{
public:
int m_x;
string m_s;
};

class B
{
public:
A m_a1;
A m_a2
};
?