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. how to display Ports Available List
Forum Updated to NodeBB v4.3 + New Features

how to display Ports Available List

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 622 Views
  • 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.
  • R Offline
    R Offline
    rezaMSLM
    wrote on last edited by
    #1

    hello
    i want to display Ports available on my computer using QSerialPortInfo::availablePorts()
    using the following code

    #include <QCoreApplication>
    #include <QtSerialPort/QSerialPort>
    #include <QtSerialPort/QSerialPortInfo>
    #include <QList>
    #include <QtDebug>
    
    int main(int argc, char *argv[])
    {
        QCoreApplication a(argc, argv);
        QSerialPortInfo s1;
        QList<QSerialPortInfo> list;
        list=s1.availablePorts();
    qDebug()<<list;
    
        return a.exec();
    }
    

    but i receive error on

    qDebug()<<list;
    

    how to convert "list" to Qstring in order to use with qDebug()?

    JonBJ J.HilkJ 2 Replies Last reply
    0
    • R rezaMSLM

      hello
      i want to display Ports available on my computer using QSerialPortInfo::availablePorts()
      using the following code

      #include <QCoreApplication>
      #include <QtSerialPort/QSerialPort>
      #include <QtSerialPort/QSerialPortInfo>
      #include <QList>
      #include <QtDebug>
      
      int main(int argc, char *argv[])
      {
          QCoreApplication a(argc, argv);
          QSerialPortInfo s1;
          QList<QSerialPortInfo> list;
          list=s1.availablePorts();
      qDebug()<<list;
      
          return a.exec();
      }
      

      but i receive error on

      qDebug()<<list;
      

      how to convert "list" to Qstring in order to use with qDebug()?

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @rezaMSLM
      I assume from http://doc.qt.io/qt-5/qdebug.html#operator-lt-lt-25

      Writes the contents of list to debug. T needs to support streaming into QDebug.

      it's not the QList that is the issue, it's that QSerialPortInfo cannot be streamed (turned into a string). You need to do that yourself, perhaps one-at-a-time instead of in one go.

      1 Reply Last reply
      3
      • R rezaMSLM

        hello
        i want to display Ports available on my computer using QSerialPortInfo::availablePorts()
        using the following code

        #include <QCoreApplication>
        #include <QtSerialPort/QSerialPort>
        #include <QtSerialPort/QSerialPortInfo>
        #include <QList>
        #include <QtDebug>
        
        int main(int argc, char *argv[])
        {
            QCoreApplication a(argc, argv);
            QSerialPortInfo s1;
            QList<QSerialPortInfo> list;
            list=s1.availablePorts();
        qDebug()<<list;
        
            return a.exec();
        }
        

        but i receive error on

        qDebug()<<list;
        

        how to convert "list" to Qstring in order to use with qDebug()?

        J.HilkJ Offline
        J.HilkJ Offline
        J.Hilk
        Moderators
        wrote on last edited by J.Hilk
        #3

        @rezaMSLM

        one way of doing it.

        int main(int argc, char *argv[])
        {
            QCoreApplication a(argc, argv);
            
            for(const QSerialPortInfo &info : QSerialPortInfo::availablePorts())
                qDebug() << info.portName();
        
            return a.exec();
        }
        

        Fixed typo.


        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


        Q: What's that?
        A: It's blue light.
        Q: What does it do?
        A: It turns blue.

        R 1 Reply Last reply
        5
        • J.HilkJ J.Hilk

          @rezaMSLM

          one way of doing it.

          int main(int argc, char *argv[])
          {
              QCoreApplication a(argc, argv);
              
              for(const QSerialPortInfo &info : QSerialPortInfo::availablePorts())
                  qDebug() << info.portName();
          
              return a.exec();
          }
          

          Fixed typo.

          R Offline
          R Offline
          rezaMSLM
          wrote on last edited by
          #4

          @J.Hilk
          I'm a newbie please post complete code. this code has compiling errors.

          J.HilkJ 1 Reply Last reply
          0
          • R rezaMSLM

            @J.Hilk
            I'm a newbie please post complete code. this code has compiling errors.

            J.HilkJ Offline
            J.HilkJ Offline
            J.Hilk
            Moderators
            wrote on last edited by J.Hilk
            #5

            @rezaMSLM well yes, I missed a closing ), you should be able to fix that yourself.

            for(const QSerialPortInfo &info : QSerialPortInfo::availablePorts())
                    qDebug() << info.portName();
            

            Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


            Q: What's that?
            A: It's blue light.
            Q: What does it do?
            A: It turns blue.

            1 Reply Last reply
            3

            • Login

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