Qt QList serialization for database

前端 未结 2 1528
囚心锁ツ
囚心锁ツ 2021-01-20 13:09

I have a QList list. I want to insert it on the database. I didn\'t find any serializer method after some googling. If there any method / idea to serialize the list data for

2条回答
  •  被撕碎了的回忆
    2021-01-20 13:41

    How about using QStringList instead of QList -

    QStringList numberList_;    // instead of QList, use this
    QString myString1 = "Hello";
    QString myString2 = "World";
    numberList_ << myString1;
    numberList_ << myString2;
    
    QByteArray byteArray;
    QBuffer buffer(&byteArray);
    QDataStream out(&buffer);
    out << numberList_;
    

    Probably QList should also work in place of QStringList. If it doesn't, well, you can convert it pretty easily to QStringList.

    QDataStream, QBuffer, QByteArray and QStringList reference.

提交回复
热议问题