Re: [Interest] QDataStream not increasing position of QByteArray

2017-10-02 Thread Thiago Macieira
On Monday, 2 October 2017 05:23:21 PDT stephan.ebel...@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

___
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest


Re: [Interest] QDataStream not increasing position of QByteArray

2017-10-02 Thread Henry Skoglund

On 2017-10-02 14:23, stephan.ebel...@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.


Here's the code:

|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 ); datastream.setByteOrder( 
QDataStream::LittleEndian ); if( udpSocket->readDataGram( buffer.data(), 
buffer.size(), &ip, &port ){ datastream.device().seek( bytePosition ); 
datastream.writeRawData( buffer.data(), buffer.size() ); bytePosition += 
240; } } |


Why is this happening?

The code works fine on Linux Mint 18 64Bit. But it's not working on 
Windows 10 64Bit. I'm using Qt Creator 4.3.1 with Qt 5.9.1.





Maybe a stupid question, but you're sure you're receiving the same 240 
network bytes in Win10 as you do in Mint? If you do a trace printout of 
the buffer.size() in receiveAppend(), is it the same in both systems?

Maybe Win10's firewall is messing the program...

Rgrds Henry

___
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest


[Interest] QDataStream not increasing position of QByteArray

2017-10-02 Thread stephan.ebel...@hs-anhalt.de

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.

Here's the code:

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 );
datastream.setByteOrder( QDataStream::LittleEndian );

if( udpSocket->readDataGram( buffer.data(), buffer.size(), &ip, &port ){
datastream.device().seek( bytePosition );
datastream.writeRawData( buffer.data(), buffer.size() );
bytePosition += 240;
}
}


Why is this happening?

The code works fine on Linux Mint 18 64Bit. But it's not working on Windows 10 
64Bit. I'm using Qt Creator 4.3.1 with Qt 5.9.1.


I appreciate your help.


Best regards

Stephan Ebeling
___
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest