Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QSerialPort Problem portName() sending empty string

QSerialPort Problem portName() sending empty string

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 1.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mahmoud899
    wrote on last edited by
    #1

    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;
         }
         else
                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

    Mahmoud Ramy

    1 Reply Last reply
    0
    • K Offline
      K Offline
      kuzulis
      Qt Champions 2020
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • S Offline
        S Offline
        shrikantd
        wrote on last edited by
        #3

        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()

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved