Permission error on opening USB dongle using QSerialPort
<p>I'm trying to access a USB dongle (which has SIM card in it) using QSerialPort.
The dongle is successful identified but when trying to open it I get permission error. The description of the error message from Qt documentation states that this could be that the device is being accessed by another service or the user has no permission. I attempted to disconnect the dongle and connect it again with the same results. How can I solve this. I'm on Ubuntu 16.04 64bit using Qt 5.7. The code I'm running is as below.</p>

<pre><code>#include &lt;QApplication&gt;
#include &lt;QString&gt;
#include &lt;QDebug&gt;
#include &lt;QList&gt;
#include &lt;QSerialPortInfo&gt;
#include &lt;QSerialPort&gt;
#include &lt;QDebug&gt;


int main(int argc, char *argv[])
{
    QList&lt;QSerialPortInfo&gt; ports = QSerialPortInfo::availablePorts();
    QSerialPort *port = nullptr;
    QString portName;
    int counter = 0;

    while(counter &lt; ports.size())
    {
        portName = ports[counter].portName();
        quint16 productId = ports[counter].productIdentifier();
        quint16 vendorId = ports[counter].vendorIdentifier();
        QString manufacturerName = ports[counter].manufacturer();

        qDebug() &lt;&lt; "Port Name: " &lt;&lt; portName;
        qDebug() &lt;&lt; "Product ID:" &lt;&lt; productId;
        qDebug() &lt;&lt; "Vendor Id: " &lt;&lt; vendorId;
        qDebug() &lt;&lt; "Manufacturer: " &lt;&lt; manufacturerName;
        ++counter;

        if(manufacturerName.contains("Huawei", Qt::CaseInsensitive))
        {
            qDebug() &lt;&lt; "found!" &lt;&lt; " name: " &lt;&lt; portName;
            port = new QSerialPort(portName);
            break;
        }
    }


    //Write and send the SMS
    bool opened = port-&gt;open(QIODevice::ReadWrite);

    if(!opened)
    {
        qDebug() &lt;&lt; "Error: " &lt;&lt; port-&gt;error();
    }

    // some more code here

    return 0;
}
</code></pre>

<p>The output is as below:</p>

<pre><code>Port Name:  "ttyS4"
Product ID: 11799
Vendor Id:  32902
Manufacturer:  ""
Port Name:  "ttyUSB0"
Product ID: 5382
Vendor Id:  4817
Manufacturer:  "HUAWEI"
found!  name:  "ttyUSB0"
Error:  QSerialPort::SerialPortError(PermissionError)
</code></pre>