title: sending qimage over qtcpsocket: received only part of the data
body: <p>i am creating an application where i need to send some images over tcp.</p>
  
  <p>the sending part is</p>
  
  <pre><code>QImage image;  
  image.load("image.png", "PNG");  
  image.setText("name", "color");  
  QByteArray ba;  
  QBuffer buffer(&amp;ba);  
  image.save(&amp;buffer, "PNG");  
  int bsize = ba.size();  
  sendData(MESSAGE_BACKGROUND_COLOR, QString::number(ba.size()).toStdString());  
  int bsent = m_tcpSocket-&gt;write(ba, ba.size());  
  if(!m_tcpSocket-&gt;waitForBytesWritten(-1))  
  {  
      qDebug() &lt;&lt; "written Bytes error " &lt;&lt; m_tcpSocket-&gt;errorString();  
  }  
  m_tcpSocket-&gt;flush();  
  </code></pre>
  
  <p>and the client:</p>
  
  <pre><code> QByteArray buffer;  
   buffer = m_ConnectedClients[i]-&gt;read(messageSize);  
   int bytesS = buffer.size();  
   QImage image;  
   image.loadFromData(buffer.data());  
   if (image.isNull())  
   {  
      qDebug("The image is null. Something failed.");  
   }  
  </code></pre>
  
  <p>The problem is that where the server seems to be sending all the data,
  the client receives only the header...<br>
  (and of-course the program crashes in line </p>
  
  <blockquote>
    <p>image.loadFromData(buffer.data());</p>
  </blockquote>
  
  <p>The tcp communication works ok, since other messages containing only text go through ok...</p>
  
  <p>Any ideas?</p>
  
  <p>Thanks in advance!</p>