[Qt-interest] Adding quint32 to a QByteArray
Jason H
scorp1us at yahoo.com
Tue Sep 7 23:23:52 CEST 2010
Why not
ds.setByteOrder(LittleEndian);
ds << num;
ds.setByteOrder(/*whatever it was*/);
?
________________________________
From: Francisco Gonzalez <gzmorell at gmail.com>
To: qt-interest at trolltech.com
Sent: Tue, September 7, 2010 5:06:36 PM
Subject: Re: [Qt-interest] Adding quint32 to a QByteArray
2010/9/7 Jason H <scorp1us at yahoo.com>
QDataStream + QBuffer?
>
>
>
>
Well in fact (from Qt Docs):
"QDataStream::QDataStream ( QByteArray * a, QIODevice::OpenMode mode )
Constructs a data stream that operates on a byte array, a. The mode describes
how the device is to be used.
Alternatively, you can use QDataStream(const QByteArray &) if you just want to
read from a byte array.
Since QByteArray is not a QIODevice subclass, internally a QBuffer is created to
wrap the byte array."
so it is the same solution.
What I mean is why there is not a function like?:
QByteArray & QByteArray::append( const quint32& num, QByteArray::ByteOrder bo);
From:Francisco Gonzalez <gzmorell at gmail.com>
To: qt-interest at trolltech.com
>Sent: Tue, September 7, 2010 2:24:12 PM
>Subject: [Qt-interest] Adding quint32 to a QByteArray
>
>
>Hello,
>Afaik QByteArray class have not a function to add a quint32 data directly at
>some position, (nor any other integer, float or doble types) in a platform
>independent manner.
>Instead it is possible to do:
>
>
>quint32 number = anyNumber;
>qint64 position = anyPositionNumber;
>QByteArray array;
>QDataStream stream(QByteArray& array, QIODevice::ReadWrite);
>stream.setByteOrder(QDataStream::LittleEndian); // The endian type you want
>stream.device()->seek(position);
>stream << number;
>
>
>
>
>Is there any other option to get this directly to a QByteArray in a platform
>independent way?
>
>
>Thanks,
>Francisco González
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100907/c8f61e54/attachment.html
More information about the Qt-interest-old
mailing list