title: Weird behavior QT QSerialPort on windows 7 doesn't change the settings of the serial com port
body: <p>I'm writing a qt bridge to access serial thermal printers by web apps.
  I'm having an issue settings serial port settings, here is my code:</p>
  
  <pre><code>bool Bridge::printToSerial(QByteArray arr, QString serialPortName, quint16 baud) {
  
  /*
  QProcess    proc;
  QStringList args = QStringList() &lt;&lt; QString("mode COM1 BAUD=%1 PARITY=%2 DATA=%3" ).arg(9600).arg( "n" ).arg(8);
  proc.start( "cmd.exe", args );
  proc.waitForStarted();
  proc.close();
  */
  
  QSerialPort* m_port = new QSerialPort(this);
  m_port-&gt;setPortName(serialPortName); // \\.\COM1
  if(!m_port-&gt;open(QSerialPort::ReadWrite)) {
     qDebug() &lt;&lt; "Error serial open";
  } else {
      if (arr.isEmpty()) {
          qDebug() &lt;&lt; QObject::tr("Either no data was currently available on the standard input for reading, or an error occurred for port %1, error: %2").arg(serialPortName).arg(m_port-&gt;errorString()) &lt;&lt; endl;
          delete m_port;
          return 1;
      }
  
      m_port-&gt;setBaudRate(baud);
      m_port-&gt;setDataBits(QSerialPort::Data8);
      m_port-&gt;setParity(QSerialPort::NoParity);
      m_port-&gt;setStopBits(QSerialPort::OneStop);
  
      //m_port-&gt;setBreakEnabled(true);
  
      qint64 bytesWritten = m_port-&gt;write(arr);
      if (bytesWritten == -1) {
          qDebug() &lt;&lt; QObject::tr("Failed to write the data to port %1, error: %2").arg(serialPortName).arg(m_port-&gt;errorString()) &lt;&lt; endl;
          delete m_port;
          return 1;
      } else if (bytesWritten != arr.size()) {
          qDebug() &lt;&lt; QObject::tr("Failed to write all the data to port %1, error: %2").arg(serialPortName).arg(m_port-&gt;errorString()) &lt;&lt; endl;
          delete m_port;
          return 1;
      } else if (!m_port-&gt;waitForBytesWritten(500)) {
          qDebug() &lt;&lt; QObject::tr("Operation timed out or an error occurred for port %1, error: %2").arg(serialPortName).arg(m_port-&gt;errorString()) &lt;&lt; endl;
          delete m_port;
          return 1;
      }
      m_port-&gt;close();
      delete m_port;
      qDebug() &lt;&lt; QObject::tr("Data successfully sent to port %1").arg(serialPortName) &lt;&lt; endl;
      return false;
  }
  delete m_port;
  return true;
  }
  </code></pre>
  
  <p>the problem is that the data prints but doesn't finish, which made me thing that data bits is not set to 8 bits.</p>
  
  <p>I executed the command: mode COM1 and it shows that the port isn't configured properly ( baud rate, bits, parity all wrong ). btw the device manager is showing the default settings of the port and a different result than the cmd line: "mode COM1"</p>
  
  <p>To make it work, I either have to execute the cmd line:
  mode COM1 BAUD=9600 PARITY=n DATA=8 before I run the program.
  or call m_port->setBreakEnabled(true); after I open the port. This call hangs the program, and I have to recompile the exe without to work.
  When the system restarts, command line mode show the old results ( baud rate 1200, data bits 7 etc )</p>
  
  <p>Any clue why I'm having this behavior ?
  It seems QSerialPort is unable to effectively change all the settings I require.</p>