title: cant read data from QTcpSocket
body: <p>I use QTcpSocket to open a connection and receive the data. But I'm having issues reading data from then socket. </p>
  
  <p>// header file</p>
  
  <pre><code>    class PeerWireClient : public QTcpSocket
  {
      Q_OBJECT
  
  public:
  
      PeerWireClient(QObject *parent = 0);
  
  private slots:
      void readFromSocket();
  
  private:
  
      qint64 socketBytesAvailable() const { return QTcpSocket::bytesAvailable(); }
      // Data waiting to be read/written
      QByteArray incomingBuf;
      QByteArray outgoingBuf;
  };
  </code></pre>
  
  <p>// cpp file</p>
  
  <pre><code>PeerWireClient::PeerWireClient(QObject *parent) :
      QTcpSocket(parent)
  {
      connect(this, SIGNAL(readyRead()), this, SLOT(readFromSocket()));
  }
  
  void PeerWireClient::readFromSocket(void)
  {
      qint64 oldsize, size;
      qint64 readbytes = 0;
  
      oldsize = incomingBuf.size();
      size = socketBytesAvailable();
      if (size &gt; 0) {
          incomingBuf.resize(oldsize + size);
          readbytes = read((incomingBuf.data()+oldsize), size);
          qDebug("%ld", readbytes); // 
          qDebug("data: %s", incomingBuf.constData());
      }
  }
  </code></pre>
  
  <p>If I try to send 281 bytes data from the other side then 
  the read function return 281 bytes but the is no data in buffer. </p>
  
  <pre><code>Debug: 
  281
  
  data: 
  </code></pre>
  
  <p>I dont know what I am doing wrong. How can I make this work?</p>