Say I have a structure like this:
class AAA
{
BBB bb_member;
double dbl_member;
....................
}
class BBB
{
int int_member;
QString QStr_member;
.................
QTextEdit m_textEdit;
}
And for AAA I define this operators:
QDataStream &operator<<(QDataStream &out, const AAA &aa)
{
out << aa.bb_member
<< aa.dbl_member;
return out;
}
QDataStream &operator>>(QDataStream &in, AAA &aa)
{
BBB bb_memb;
double dbk_memb;
in >> bb_memb
>> dbk_memb;
aa = AAA(bb_memb, dbk_memb);
return in;
}
Then I call this:
QFile file("myFileName");
file.open(QIODevice::WriteOnly))
QDataStream out(&file);
out << AAA_object;
in order to serialize AAA object to a file.
Now the question. How I should define QDataStream operators for BBB class in order to serialize BBB object (int, QString and QTextEdit reach text content), while calling out << AAA_object; ???
See Question&Answers more detail:os