PDA

View Full Version : Store QList<T> in QVariant and stream to QDataStream?



razvan.petru
17th September 2009, 21:42
Hi,
I'm trying to do what the title suggests...

QList<Custom> L;
QVariant v(QVariant::fromValue(l));
QDataStream d;
d << v;

The problem seems to be that d doesn't know how to stream v, because v doesn't know how to do a metatype save on L. I have registered Custom and L as metatypes and I've also registered their IO streams, but L has no meta object, and I think that is the problem.

Can I get around this somehow?

wysota
17th September 2009, 22:17
There is no free beer here :) You have to implement proper streaming operators yourself.

Use this:

void qRegisterMetaTypeStreamOperators ( const char * typeName )

razvan.petru
18th September 2009, 08:58
I did register them, but it doesn't work. The specific error that I get at runtime is "ASSERT failure in QVariant::save: "Invalid type to save", file kernel\qvariant.cpp, line 1952".

Later edit: the problem was that when calling qRegisterMetaTypeStreamOperators<CustomList>("clist"), "clist" should have been "CustomList", the string matters!

wysota
18th September 2009, 09:10
Sure it matters :) It has to be identical to what's returned by the metatype.