Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Serialising variants - QVector<int>() from value.

Serialising variants - QVector<int>() from value.

Scheduled Pinned Locked Moved Solved General and Desktop
qvariantserializationserialize
1 Posts 1 Posters 966 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Dariusz
    wrote on 15 Aug 2019, 17:32 last edited by Dariusz
    #1

    Hey

    And I'm stuck, I have a

    QMap<int,QMap<int,QVariant>> as my data structure in my treeView.
    

    I was trying to serialize it but I keep getting >

    WARNING: QVariant::save: unable to save type 'QVector<int>' (type id: 1033).
    
     (kernel\qvariant.cpp:2593, void __cdecl QVariant::save(class QDataStream &) const)
    

    As far as I can tell, I have 7 items in my map and some of them are :

    QVector<int> data;
    QVariant::fromValue(data);
    

    Other than that I don't see other issues, when I look in debug at the map some of variatns have no value at all and others have (invalid) as flag next to them...

    Mhmhmmhmmm....

    What did I do ? :- )


    Kay so I did some digging, looks like I have to register it and somehow implement...but how?

        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;
    

    returns the same error...


    Tried adding this above main... still no luck...

    QDataStream &operator<<(QDataStream &out, const QVector<int> &vec) {
        out << vec.size();
        for (auto &v:vec) {
            out << v;
        }
        return out;
    };
    
    
    int main(int argc, char *argv[]) {
    

    Answer :

    Needed to add :

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

    I really wish that Docs would explain that... "easier" or mention it somehow. Took a while to read a whole bunch of info to realize this :/

    1 Reply Last reply
    0

    1/1

    15 Aug 2019, 17:32

    • Login

    • Login or register to search.
    1 out of 1
    • First post
      1/1
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved