views:

289

answers:

1

Hi,
Here's the demo code:

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?

Later edit:
After debugging the QMetaType code, I've found out that when calling qRegisterMetaTypeStreamOperators<Type>("TypeString") "TypeString" must be "Type", not just any string. This was mentioned in the docs, but it's not really clear. The QtCentre link also mentioned this. I've decided to accept Kaleb Pederson's answer because it is my fault that I found the answer the hard way. :)

+1  A: 

You need to register output operators for the given type. See also a similar question on QtCentre.

What this implies is that you need to define non-member output operators matching the signature defined in the documentation and then call qRegisterMetaTypeStreamOperators.

Kaleb Pederson
The key was in your QtCentre link: the type name must match the string in qRegisterMetaTypeStreamOperators!
rpg