title: QTcpSocket Read Error
body: <p>I have a Qt based TCP client and server making use of QTcpServer and QTcpSocket classes for communication. The server is compiled using Qt 5.3.1 and the client is compiled using Qt 4.8.1. This is done so because the client is a part of a framework that uses Qt 4.8.1 running on Ubuntu 12.04.</p>
  
  <p>Since the classes I make use is available in both Qt versions I assume this wont create a problem.</p>
  
  <p>However my client has some weird issues that it does not receive data from the server! I checked the server side and the data is sent from the server and I can also see the data packet on the wire using wireshark. However on my client code, the data does not arrive!</p>
  
  <p>I investigated this a bit and it led me to a strange conclusion that this happens only if I use the read method of QTcpSocket! If I use the native POSIX read system call, I am able to read the data correctly! Please see my code below:</p>
  
  <pre><code>qDebug() &lt;&lt; "QTcpSocket::bytesAvailable() gives" &lt;&lt; m_pSocket-&gt;bytesAvailable();
  
  char nData;
  
  qint32 szReceived;
  
  if(sizeof(char) != (szReceived = m_pSocket-&gt;read((char*)&amp;nData,sizeof(char))))
  {
      qDebug() &lt;&lt; "Error reading data from QTcpSocket::read()" &lt;&lt; m_pSocket-&gt;errorString();
  }
  else
  {
      qDebug() &lt;&lt; "QTcpSocket::read() returned" &lt;&lt; szReceived;
  }
  
  int nDesc = m_pSocket-&gt;socketDescriptor();
  
  if(sizeof(char) != (szReceived = read(nDesc, &amp;nData,sizeof(char))))
  {
      perror("Error reading data from POSIX read()");
  }
  else
  {
      qDebug() &lt;&lt; "POSIX read() returned" &lt;&lt; szReceived;
  }
  </code></pre>
  
  <p>This produces the following output:</p>
  
  <pre><code>QTcpSocket::bytesAvailable() gives 0 
  Error reading data from QTcpSocket::read() "Network operation timed out" 
  POSIX read() returned 1
  </code></pre>
  
  <p>How is it that the POSIX system calls reads the buffered data as expected and the Qt class cannot read it? Plus I have not set any socket options and so I don't know why it reports an error that network operation timed out!</p>