Qt 5 -> Qt 6 Stream operator for QVariant
-
I created a class that overloads the stream operator to read binary data. The implementation streams several variables to unpack a binary file like below:
QDataStream &operator >>(QDataStream &stream,KItem &item) { stream >> item.itemTargetType; stream >> item.itemTarget; stream >> item.itemLabelName; stream >> item.itemLabelFont; stream >> item.itemLabelforegroundColor; stream >> item.itemLabelbackgroundColor; stream >> item.lockAspectRatio; stream >> item.itemImagePixmap; stream >> item.itemImageSize; stream >> item.datatagFilename; stream >> item.datatagTreeValues; return stream; }
Everything worked fine in 5.15.2 but in 6.4.3 all the variables but the last one load. It's very nested along the lines of QHash<QString, QVariant> And the QVariant contains QVariantLists of QVariants, QPixmaps, QStringLists, and QDateTime. All these types are in QMetaType but they aren't loading and I get an empty QHash with this in the output:
Trying to construct an instance of an invalid type, type id: 65
Trying to construct an instance of an invalid type, type id: 16640
Trying to construct an instance of an invalid type, type id: 16640
Trying to construct an instance of an invalid type, type id: 18432
Trying to construct an instance of an invalid type, type id: 3539043Does the nested QMetaTypes need to be registered as it's own type? If so, I don't know how to go about that since the QVariantList can contain a variable number and structure of QMetaTypes.
-
@ChrisW67 Excellent! That was the issue and all bugs resolved. Quite the ctrl+F exercise for my entire project but I don't see another way around. Looks like support for previous stream versions will be there for a while. Thanks for the fast reply!