[Qt-interest] Adding quint32 to a QByteArray

Andre Somers andre at familiesomers.nl
Wed Sep 8 09:13:54 CEST 2010


  Op 7-9-2010 20:24, Francisco Gonzalez schreef:
> 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
>
I don't think what you want - writing in the middle of an existing data 
array - is supported. But perhaps you can write out the quint32 to a 
small buffer using QDataStream, and copy the raw bytes of that buffer to 
the position in the byte array you want it?

André




More information about the Qt-interest-old mailing list