Details
-
Suggestion
-
Resolution: Unresolved
-
Not Evaluated
-
None
-
5.4.2
-
None
Description
QDataStream::readBytes is cumbersome to use and not very c++ : you need to pass a reference to a free pointer and a reference to a size, the function will set this pointer to a buffer allocated with [] and set the size accordingly:
uint size = 0; char * buf = 0; datastream.readBytes(buf, size); //Do something with the data... delete[] buf;
This is a pure C approach and prone to memory leaks.
Why not just returning a QByteArray?
Same for QDataStream::writeBytes, but this is less a problem as one can write:
QDataStream::writeBytes(ba.data(), ba.size());
We just need :
QByteArray ba; datastream.writeBytes(ba); QByteArray ba = datastream.readBytes();