Im trying to send webcam images to another machine, I want them to be sent using JPG.
I have tried several more complex attempts (with QByteArrray and sending total block size beforehand) where I always got black images on the other side but searching this forums I came out with this very minimal version:
In the sender (a thread that receive a socket and connect , this part is working)
writer.write(currentImage);
if(!socket->waitForBytesWritten())
qWarning()<<"ERROR: Unable to send image: "<<socket->
Q_ASSERT(socket->state() == QAbstractSocket::ConnectedState);
QDataStream stream(socket);
stream.setVersion(QDataStream::Qt_4_5);
QImageWriter writer(stream.device(), "JPG");
writer.write(currentImage);
if(!socket->waitForBytesWritten())
qWarning()<<"ERROR: Unable to send image: "<<socket->
To copy to clipboard, switch view to plain text mode
In the reader
if(!this->socket->waitForReadyRead())
{
qWarning()<<"ERROR: could not read image: "<<socket->errorString();
return;
}
QImageReader reader
(stream.
device(),
"JPG");
// &image_buffer, "JPG");
if(!reader.read(this->img->image())) {
qWarning()<<"ERROR: Unable to read received image from buffer: "<<reader.errorString();
return;
}
if(!this->socket->waitForReadyRead())
{
qWarning()<<"ERROR: could not read image: "<<socket->errorString();
return;
}
QImageReader reader(stream.device(), "JPG"); // &image_buffer, "JPG");
if(!reader.read(this->img->image())) {
qWarning()<<"ERROR: Unable to read received image from buffer: "<<reader.errorString();
return;
}
To copy to clipboard, switch view to plain text mode
This version will not working at all
The reader willl print
ERROR: Unable to read received image from buffer: "Unable to read image data"
ERROR: could not read image: "The remote host closed the connection"
Just as if notheing is sent.
I-m sure that the problem is obvious ...
Bookmarks