Important: Please read the Qt Code of Conduct -

QSerialPort Problem portName() sending empty string

  • Hello, I want to start using the QSerialPort library but I am having some difficulties with it. I have downloaded the Qt Creator 5.1 and in the installation I have installed the qserialport library. I added "Qt += serialport" to my .pro file. I made a new console project and this is the code

    #include <QCoreApplication>
    #include <QSerialPort/QSerialPort>
    #include <QSerialPort/QSerialPortInfo>
    #include <QString>
    #include <QTextStream>

    int main( int argc, char *argv[])
    QCoreApplication a(argc, argv);
    QTextStream output(stdout);
    QSerialPortInfo port;
    QString portName;

         portName = port.portName();
         if ( portName.isEmpty())
                 output << "Empty String" << endl;
                output << portName << endl;


    The problem here is that it prints out an "Empty String". I have looked into the Windows Device Manager and I have found that I have Communications Port(COM1) and Printer Port(LPT1). I am using Windows XP. Any suggestions on why the program is not printing the serial port name? Thank you

  • Qt Champions 2020

    And you read documentation, looked examples? You itself understand, what you do? Otherwise I don't want to help you at all...

  • You need to provide name through the constructor for QSerialPortInfo() and should check for ports presence using isValid().
    One can also enumerate through available ports using QSerialInfo::availablePorts()

Log in to reply