title: How to make QSerialPort from Qt5.13.1 work?
body: <h1>Problem</h1>
  
  <p><code>QSerialPort</code> from version 5.13.1 of the Qt library does not physically output data under Windows 7 and 10.</p>
  
  <h1>Example</h1>
  
  <p>In order to demonstrate the described problem I have prepared the following setup:</p>
  
  <ol>
  <li>Hardware</li>
  </ol>
  
  <p>I have tested the connection between a PC with a physical serial port (COM1) and a real serial device, but for demonstration purposes I have created a simple loopback by connecting together pins 2 and 3 of the DSub connector of the PC, i.e. Tx and Rx.</p>
  
  <ol start="2">
  <li>Software</li>
  </ol>
  
  <p>The problem occurs in my own GUI applications, as well as in the official examples shipped with Qt. However, for the sake of the demonstration I wrote a very basic console app:</p>
  
  <p><em>SerialBug.pro</em></p>
  
  <pre><code>QT -= gui
  QT += serialport
  
  CONFIG += console
  
  SOURCES += \
          main.cpp
  </code></pre>
  
  <p><em>main.cpp</em></p>
  
  <pre><code>#include &lt;QCoreApplication&gt;
  #include &lt;QSerialPort&gt;
  #include &lt;QDebug&gt;
  
  int main(int argc, char *argv[])
  {
      QCoreApplication a(argc, argv);
  
      QSerialPort port("COM1");
  
      port.setBaudRate(QSerialPort::Baud4800);
      port.setDataBits(QSerialPort::Data8);
      port.setStopBits(QSerialPort::OneStop);
      port.setParity(QSerialPort::NoParity);
      port.setFlowControl(QSerialPort::NoFlowControl);
  
      QObject::connect(&amp;port, &amp;QSerialPort::readyRead,
                       [&amp;port](){
          qDebug() &lt;&lt; port.readAll();
      });
  
      QObject::connect(&amp;port, &amp;QSerialPort::bytesWritten,
                       [](qint64 bytes){
          qDebug() &lt;&lt; bytes;
      });
  
      QObject::connect(&amp;port, &amp;QSerialPort::errorOccurred,
                       [](QSerialPort::SerialPortError error){
          qDebug() &lt;&lt; error;
      });
  
      if (port.open(QSerialPort::ReadWrite)) {
          qDebug() &lt;&lt; port.write("Test");
      }
  
      return a.exec();
  }
  </code></pre>
  
  <h1>Result</h1>
  
  <p>Compiling and running the example code with MSVC2017 and Qt 5.13.0 in release mode, the following output is produced:</p>
  
  <pre><code>QSerialPort::NoError
  4
  4
  "Test"
  </code></pre>
  
  <p>The exact same code compiled in release mode with MSVC2017, but this time with Qt 5.13.1, produces the following output:</p>
  
  <pre><code>QSerialPort::NoError
  4
  </code></pre>
  
  <p><code>port.write</code> returns <code>4</code>, meaning 4 bytes are send to the serial port, but that is not actually done. <code>bytesWritten</code> is not emitted and the data is not read back.</p>
  
  <p><strong>Note:</strong> A serial monitor program is showing the written data, but the data does not reach the pins.</p>
  
  <p>Is it possible to fix the code in any way in order to make it work with Qt5.13.1?</p>