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)
Qt Code:
  1. Q_ASSERT(socket->state() == QAbstractSocket::ConnectedState);
  2.  
  3. QDataStream stream(socket);
  4.  
  5. stream.setVersion(QDataStream::Qt_4_5);
  6.  
  7. QImageWriter writer(stream.device(), "JPG");
  8. writer.write(currentImage);
  9.  
  10. if(!socket->waitForBytesWritten())
  11. qWarning()<<"ERROR: Unable to send image: "<<socket->
To copy to clipboard, switch view to plain text mode 


In the reader

Qt Code:
  1. if(!this->socket->waitForReadyRead())
  2. {
  3. qWarning()<<"ERROR: could not read image: "<<socket->errorString();
  4. return;
  5. }
  6. QImageReader reader(stream.device(), "JPG"); // &image_buffer, "JPG");
  7.  
  8. if(!reader.read(this->img->image())) {
  9. qWarning()<<"ERROR: Unable to read received image from buffer: "<<reader.errorString();
  10. return;
  11. }
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 ...