title: QSerialPort - wating for whole data from sender
body: <p>I'm working with a serial device.
  The QSerialPort is in a separate thread.
  Thread is created this way:</p>
  
  <pre><code>QThread* serialthread = new QThread;
  Serial*  serial = new Serial();
  serial-&gt;moveToThread(serialthread);
  </code></pre>
  
  <p>When Data is available this signal in my thread worker is emited:</p>
  
  <pre><code>    void Serial::process()
      {
          serialport = new QSerialPort();
          connect(this-&gt;serialport,SIGNAL(readyRead()),this,SLOT(readyToRead()));
      }
      void Serial::readyToRead()
      {
          emit SIG_dataAvailable(this-&gt;read());
      }
  </code></pre>
  
  <p>This is the function that reads the data and checks if the data is correct - the second byte on my serial device says how long the rest of the packet is...</p>
  
  <pre><code>QByteArray Serial::read() const
  {
      QByteArray receivedData;
      int length;
      receivedData = serialport-&gt;readAll();
      length = receivedData[1];
      if(length != receivedData.length() - 1)
      {
          qDebug() &lt;&lt; "protocol error.";
          return NULL;
      }
      return receivedData;
  }
  </code></pre>
  
  <p>My problem is that the signal QSerialPort::readyRead is emited before the data from the serial device is complete in the buffer. Any idea how to solve this problem?</p>