title: QT 5.7 Serial Port reads very slow
body: <p>I am very new to programming and I am teaching myself. I wrote a application to poll a number of requests from a control unit . I basically continuously send various read commands to the Control unit and read back the response .My program works and i successfully send commands and receive answers . But the reading is very slow ( i have a 100 ms timeout in my code to ensure i get the complete reply ) 
  I have a program for the same control unit that was written by a professional coder in C++ , in his program he polls every 30 ms and i always receive the complete answer in that time frame . I have the same settings 57K baud 8 bits 1 stop bit and no parity . However my QT code takes almost 100 ms to receive the answer.
  In my code i read the first 2 bytes ( first byte is the message identifier and second byte is the remainder of the message length) then i read in a loop until the total message length is equal to the message length byte +1 (the +1 is there to include the first byte ) . I am a wits end as to why my code is so slow in QT when i know its know the Hardware that's the limiting factor . The requests are always 3 bytes and the reply varies from 3 to 61 bytes . Please help me to point me to my error. If i remove the timeout i always have short reads . So far i also tried read(all) but with the same result .
  Below is the extract from my code where i read the response . The full code is at <a href="https://github.com/MarkusIppy/PowerTune" rel="nofollow noreferrer">https://github.com/MarkusIppy/PowerTune</a></p>
  
  <pre><code>//Error handling 
  QTime startTime = QTime::currentTime(); 
  int timeOut = 100; // timeout in milisec. 
  QByteArray recvData = m_serialport-&gt;read(2);  // reading first two bytes of received message to determine lenght of ecpected message 
  int msgLen = recvData[1]; //Total message Lenght excluding the first byte 
  while ( recvData.size() &lt;= (msgLen+1) ) 
  { 
      if ( startTime.msecsTo(QTime::currentTime()) &gt; timeOut ) break; 
      recvData += m_serialport-&gt;read(msgLen+1-recvData.size()); 
  } 
  
  if (msgLen +1 == recvData.length())  //if the received data lenght equals the message lenght from lenght byte + identifier byte (correct message lenght received ) 
  { 
      qDebug() &lt;&lt; "Received data OK"&lt;&lt;msgLen +1; 
      if(requestIndex &lt;= 61){requestIndex++;} 
      else{requestIndex = 58;} 
      readData(recvData); 
  } 
  else   //if the lenght of the received message does not correspond with the expected lenght repeat the request 
  { 
      qDebug() &lt;&lt; "Received data lenght NIO"; 
      readData(recvData); 
      qDebug() &lt;&lt; "Request Message again"&lt;&lt; requestIndex; 
  }
  </code></pre>