[Qt-interest] Serialize QList<qint64>
Bruno Tezine
bruno at tezine.com
Wed Jul 27 21:41:07 CEST 2011
Hi Murphy,
It doesn't work.
If you try something simple like:
QList<qint64> list;
list<<1;
QVariant::fromValue(list);
It will not even compile under Windows MSVC2008 and Qt4.7.2.
Em 27/07/2011 16:18, Murphy, Sean M. escreveu:
> You shouldn't have to do anything if you're willing to accept Qt's built in serialization of a QList<T>:
> http://doc.trolltech.com/4.7/qlist.html#operator-lt-lt-77
>
> Sean
>
> -----Original Message-----
> From: qt-interest-bounces+sean.murphy=gd-ais.com at qt.nokia.com [mailto:qt-interest-bounces+sean.murphy=gd-ais.com at qt.nokia.com] On Behalf Of Bruno Tezine
> Sent: Wednesday, July 27, 2011 3:05 PM
> To: qt-interest at qt.nokia.com
> Subject: [Qt-interest] Serialize QList<qint64>
>
> Hi,
> How can I serialize a QList<qint64>?
> I already can serialize any class of mine, but I didn't figure it out on
> how to serialize a simple QList<qint64>.
> Whenever I try to serialize it, I get the assert saying "Invalid type to
> save". Any ideas? Thanks/Bruno.
>
> I registered the data type:
> qRegisterMetaType<QList<qint64> >();
> qRegisterMetaTypeStreamOperators<QList<qint64> >("QList<qint64>");
>
> Registered the stream operators:
> QDataStream&operator<<(QDataStream&stream, const QList<qint64> &d);
> QDataStream&operator>>(QDataStream&stream, QList<qint64> &d);
>
> ...and here is the implementation(it's never called):
> QDataStream&operator<<(QDataStream&stream, const QList<qint64> &d)
> {
> stream<<(quint32)0xA0B0C0D0; //Magic Number
> stream<<d.count();
> foreach(qlonglong number, d)
> stream<<number;
> return stream;
> }
>
> QDataStream&operator>>(QDataStream&stream, QList<qint64> &d)
> {
> quint32 magic;
> stream>> magic;
> if (magic != 0xA0B0C0D0)
> {
> BLogger::log(LogTypeError,NULL,"deserializing","Invalid magic
> number");
> return stream;
> }
> int listCount;
> stream>>listCount;
> QList<qlonglong> list;
> for(int i=0;i<listCount;i++)
> {
> qlonglong temp;
> stream>>temp;
> list.append(temp);
> }
> d=list;
> return stream;
> }
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at qt.nokia.com
> http://lists.qt.nokia.com/mailman/listinfo/qt-interest
More information about the Qt-interest-old
mailing list