Yes. If you declare a QVector<Thingy*> then "T" is "Thingy*". If you then rely on the default, templated, operator>>() then you get the warning. The code that generates the warning looks like:
template<typename T>
QDataStream& operator>>(QDataStream& s, QVector<T>& v)
{
v.clear();
quint32 c;
s >> c;
v.resize(c);
for(quint32 i = 0; i < c; ++i) {
T t;
s >> t;
v[i] = t;
}
return s;
}
template<typename T>
QDataStream& operator>>(QDataStream& s, QVector<T>& v)
{
v.clear();
quint32 c;
s >> c;
v.resize(c);
for(quint32 i = 0; i < c; ++i) {
T t;
s >> t;
v[i] = t;
}
return s;
}
To copy to clipboard, switch view to plain text mode
Line 9 and 10 effectively read:
Thingy* t;
s >> t;
Thingy* t;
s >> t;
To copy to clipboard, switch view to plain text mode
Under these circumstances t is indeed not initialised (i.e. it's an invalid pointer). The program might compile but it will crash.
You cannot persist a pointer between sessions and expect to get the object it pointed to back at the other end. You should be able to provide a specific implementation of:
QDataStream& operator>>(QDataStream& s, QVector<Thingy*>& v);
// and
QDataStream& operator<<(QDataStream& s, const QVector<Thingy*>& v);
QDataStream& operator>>(QDataStream& s, QVector<Thingy*>& v);
// and
QDataStream& operator<<(QDataStream& s, const QVector<Thingy*>& v);
To copy to clipboard, switch view to plain text mode
that the compiler should use in preference to the templated versions. These versions would have to arrange serialisation/deserialisation of the objects pointed to by each of the vector member pointers.
Bookmarks