Ensuring QSerialPort.close completes before program execution finishes?
<p>I have an application using a QSerialPort, the very last thing my program does is call my closePort function which looks like this:</p>

<pre><code>//Closes the port when we're done with it
void SerialCommSession::closePort()
{
    connected = false;
    if(m_port.isOpen())
    {
        qDebug() &lt;&lt; "closing port";
        m_port.close();
    }
}
</code></pre>

<p>Some amount of the time it works fine, and the program starts up again without any issue. But maybe 75% of the time, when I try to run the program again it fails to open the port, returning error code 2. How long should QSerialPort.close() take to execute? And how can I ensure it completes?</p>