title: Qt5 - ASSERT: "bytesTransferred == writeChunkBuffer.size()"
body: <p>I've written a tool which uses the QSerialPort to write to a serial device. It runs for a certain time until I get the following error message:</p>
  
  <blockquote>
    <p>ASSERT: "bytesTransferred == writeChunkBuffer.size()" in file
    qserialport_win.cpp, line 511</p>
  </blockquote>
  
  <p>My sending function looks like this:</p>
  
  <pre><code>/**
   * @brief Send text to device
   * @param text
   * @return Success/Fail
   */
  bool Serial::send(QString text)
  {
      if (connectionStatus &amp;&amp; qsp.isWritable()) {
          QByteArray buffer = text.toLatin1();
  
          if (buffer.size() != qsp.write(buffer))
              qDebug() &lt;&lt; "Send does not work";
  
          qsp.flush();
          msleep(15);
  
          return true;
      } else {
          return false;
      }
  }
  </code></pre>
  
  <p>If I understand it correctly I write the text (which is around 20 chars) with flush to the device, wait 15ms and repeat it afterwards. I don't really understand why I get this message?</p>
  
  <p>// EDIT:</p>
  
  <p>After some time I figured out what the problem was. I forgot to mention, why I wait 15 ms. That was part of the documentation, to wait after I send the data. The biggest problem, related to sending data was, that I run QSerialPort in a separate thread. By using that I run in trouble. I moved it to the MainThread and use signal slot design by Qt.</p>