[Interest] QDataStream not increasing position of QByteArray

Thiago Macieira thiago.macieira at intel.com
Mon Oct 2 18:02:12 CEST 2017


On Monday, 2 October 2017 05:23:21 PDT Stephan.Ebeling at hs-anhalt.de wrote:
> Dear Qt-list-members,
> 
> 
> 
> i got the following problem with Qt and i hope that you can help me:
> 
> 
> When I write raw network bytes to a QDataStream object repeatedly, the
> QDataStream never increases the write position of the underlying
> QByteArray.

What write position of a QByteArray? The write position belongs to the 
QDataStream, not the array.

> QByteArray recvBuf;
> int bytePosition = 0;
> 
> void init( ){
>     recvBuf = QByteArray( 240 * 10, Qt::Uninitiliazed );
> }
> 
> void receiveAppend( ){
>     QByteArray buffer( 240, Qt::Uninitialized );
>     QDataStream datastream( recvBuf, QIODevice::WriteOnly );

This line doesn't compile. I assume you meant
	QDataStream datastream( &recvBuf, QIODevice::WriteOnly );

>     datastream.setByteOrder( QDataStream::LittleEndian );
> 
>     if( udpSocket->readDataGram( buffer.data(), buffer.size(), &ip, &port ){

You should try the receiveDatagram() function.

> 	datastream.device().seek( bytePosition );

datastream.device() here is a QBuffer that QDataStream created internally to 
wrap the QByteArray.

>         datastream.writeRawData( buffer.data(), buffer.size() );
>         bytePosition += 240;
>     }
> }
> 
> 
> Why is this happening?

Why is what happening? What is the issue?

Describe what's happening and what you expected to happen.

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center




More information about the Interest mailing list