title: Qt QTcpSocket async write
body: <p>I'm trying to write a dynamic data to a QTcpSocket, this is how I implement it:</p>
  
  <pre><code>    connect(&amp;m_tcpSocket, SIGNAL(bytesWritten(qint64)), SLOT(written(qint64)));
  //...
  void MyClass::written(qint64 iBytes)
  {
      if(iBytes&gt;0)
          m_strWrite = m_strWrite.mid(iBytes);
      if(m_strWrite.length()&lt;1)
      {
          if(m_hHandle-&gt;isDone())
              m_tcpSocket.disconnectFromHost();
      }else if(m_tcpSocket.isValid()){
          m_tcpSocket.write(m_strWrite);
      }
  }
  //...
  void MyClass::dataReady(const QByteArray &amp;strData)
  {
      bool bWrite = m_strWrite.isEmpty();
      m_strWrite.append(strData);
      if(bWrite)
          written(0);
  }
  </code></pre>
  
  <p>dataReady is a slot which is called whenever there is some data ready, and strData is at most 8192 bytes.</p>
  
  <p>This method works perfectly, but when data is huge (>500 MB), strange things happen, sometimes data is written much more than what I expect, sometimes some data is missing, sometimes nothing is written after a while and ...</p>
  
  <p>I just want dynamic buffer, be written to socket, is there another way for that?</p>