title: Qt serial port: write and read data
body: <p>I'm able to connect to my serial port, but I need to read data from it all the time.<br>
  It's working for about 39 minutes, but after it stops at line <code>serial.flush()</code>.<br>
  When I stop Qt and start it again it also stops at <code>serial.flush()</code>.  I need to restart my modem to let it work again...  </p>
  
  <p>I'm not sure I'm executing this properly...</p>
  
  <pre><code>// Open Serial connexion
  QSerialPort serial;
  serial.setPortName("usbserial-26214A");
  serial.open(QIODevice::ReadWrite);
  serial.setBaudRate(QSerialPort::Baud115200);
  serial.setDataBits(QSerialPort::Data8);
  serial.setParity(QSerialPort::NoParity);
  serial.setStopBits(QSerialPort::OneStop);
  serial.setFlowControl(QSerialPort::HardwareControl);
  
  if (serial.isOpen() &amp;&amp; serial.isWritable())
  {
  qDebug() &lt;&lt; "Serial is open";
  
  QByteArray output;
  QByteArray input;
  
    while(true)
    {
    output = "AT+CPMS=\"SM\"\r";
    serial.write(output);
    serial.flush();
    serial.waitForBytesWritten(1000);
    serial.waitForReadyRead(1000);
    input = serial.readAll();
    }
  }
  </code></pre>
  
  <p>//EDIT  </p>
  
  <p>if deleting <code>flush</code> it's working, but code goes really fast. It don't wait for <code>WaitFor...</code><br>
  After 2nd loop he doesn't has time to read data.  </p>
  
  <p><code>serial.isOpen() &amp;&amp; serial.isWritable()</code> always sends <code>true</code> in while loop.  </p>
  
  <p><strong>Program stops at <code>flush</code> after 30 minutes!</strong></p>