Quick fix just call QDataStream::setVersion(QDataStream::Qt_4_6) when creting your QDataStream.
Yes I already do this.
Its maybe best if I show some actual code. Here the client sends the data to the server:
// write header to socket
for( int i=0; i<frames.size(); i++ ) {
QImage image
(fi.
absoluteFilePath());
stream2 << quint32(0) << image;
stream2.device()->seek(0);
stream2 << quint32(block2.size() - sizeof(quint32));
socket.write(block2);
socket.flush();
socket.waitForBytesWritten();
}
// write header to socket
for( int i=0; i<frames.size(); i++ ) {
QFileInfo fi = frames.at(i);
QImage image(fi.absoluteFilePath());
QByteArray block2;
QDataStream stream2(&block2, QIODevice::WriteOnly);
stream2.setVersion(QDataStream::Qt_4_6);
stream2.setByteOrder(QDataStream::LittleEndian);
stream2 << quint32(0) << image;
stream2.device()->seek(0);
stream2 << quint32(block2.size() - sizeof(quint32));
socket.write(block2);
socket.flush();
socket.waitForBytesWritten();
}
To copy to clipboard, switch view to plain text mode
And here is the code where the server reads the data:
// read header from socket
for( int i=0; i<nrFrames; i++) {
quint32 nrBytes;
waitForBytes(&socket, sizeof(quint32), 30000); // wait max 30 seconds on socket until sizeof(quint32) has arrived on socket
in >> nrBytes;
qDebug() << "nrBytes: " << nrBytes;
waitForBytes(&socket, nrBytes, 30000); // wait max 30 seconds on socket until nrBytes has arrived on socket
in >> image;
// process image
}
QDataStream in(&socket);
in.setByteOrder(QDataStream::LittleEndian);
in.setVersion(QDataStream::Qt_4_6);
// read header from socket
for( int i=0; i<nrFrames; i++) {
quint32 nrBytes;
QImage image;
waitForBytes(&socket, sizeof(quint32), 30000); // wait max 30 seconds on socket until sizeof(quint32) has arrived on socket
in >> nrBytes;
qDebug() << "nrBytes: " << nrBytes;
waitForBytes(&socket, nrBytes, 30000); // wait max 30 seconds on socket until nrBytes has arrived on socket
in >> image;
// process image
}
To copy to clipboard, switch view to plain text mode
Here is an example output what happens when the server is running on QtSdk 2010.05:
nrBytes: 39232
nrBytes: 38512
nrBytes: 40923
...
nrBytes: 2043430232
Obviously a single QImage is less than 2GB so the waitForBytes function timeouts and the socket closes. But I must say this is really strange that this happens because this code has been unchanged and has run on several production servers for almost 2 years without problems.
Note: I dont know if this is related with the data corrupt issue I was describing, but when trying the code on another machine with qtsdk-2010.05 the server outputs:
"Reading ras files from sequential devices not supported"
each time it reads a qimage and the image. I am sending Qimage instances loaded from PGM files if that makes any difference.
Bookmarks