Store QList <T> in QVariant and pass to QDataStream?

Here is a demo code:

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

The problem is that d does not know how to pass stream v, because v does not know how to make the save metatype on L. I registered Custom and L as metatypes, and I also registered them IO but L does not have a meta object, and I I think this is a problem.

Can I get around this somehow?

Edit later:
After debugging the QMetaType code, I found that when calling qRegisterMetaTypeStreamOperators<Type>("TypeString")“TypeString” there should be a “Type”, and not just any string. This has been mentioned in the docs, but it is not entirely clear. The QtCentre link also mentioned this. I decided to accept Caleb Pederson's answer, because it is my fault that I found the answer the hard way. :)

+3
1

. . QtCentre.

, , , , , qRegisterMetaTypeStreamOperators.

+2

Source: https://habr.com/ru/post/1717939/


All Articles