serializationqvariantqdatastream

How to save/serialize QVariant that is QVector<int>


I'm lost as to how to fix this :

  qRegisterMetaType<QVector<int>>("QVector<int>");

    QMap<int, QVariant> wah;
    wah[0] = QVariant::fromValue(QVector<int>{12, 231, 45, 125, 123, 12, 312, 4, 12});
    qDebug() << wah;

    QByteArray ar;
    QDataStream s(&ar, QIODevice::WriteOnly);
    s << wah;

Any ideas/help would be great. Most of the google results are about serializing custom classes and not ints :/

TIA!


Solution

  • Needed to add

    qRegisterMetaTypeStreamOperators<QVector<int>>("QVector<int>");
    

    Bit of a bummer that this is not explained in docs tho.