As a general advise: use the debugger and walk through and you will see, what happens.
Or browse the source code - Qt is open source, though it's easy to see how things are implemented.
Back to your question:
template <typename T>
QDataStream& operator<<(QDataStream& s, const QList<T>& l)
{
s << quint32(l.size());
for (int i = 0; i < l.size(); ++i)
s << l.at(i);
return s;
}
template <typename T>
QDataStream& operator<<(QDataStream& s, const QList<T>& l)
{
s << quint32(l.size());
for (int i = 0; i < l.size(); ++i)
s << l.at(i);
return s;
}
To copy to clipboard, switch view to plain text mode
This is the implementation of the operator you are talking about. (qdatastream.h:239 - Qt 4.3.2)
As you see the size of the list is written to the stream. Next all elements are written.
The elements need to implement the operator<< and operator >>.
Have all look at qdatetime.h and qdatetime.cpp how this looks like:
...
class QDate
...
friend Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QDate &);
friend Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QDate &);
To copy to clipboard, switch view to plain text mode
{
return out << (quint32)(date.jd);
}
...
{
quint32 jd;
in >> jd;
date.jd = jd;
return in;
}
QDataStream &operator<<(QDataStream &out, const QDate &date)
{
return out << (quint32)(date.jd);
}
...
QDataStream &operator>>(QDataStream &in, QDate &date)
{
quint32 jd;
in >> jd;
date.jd = jd;
return in;
}
To copy to clipboard, switch view to plain text mode
Good luck,
Tom
Bookmarks