Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    Solved how to display Ports Available List

    General and Desktop
    3
    5
    363
    Loading More Posts
    • 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
      rezaMSLM last edited by

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

      JonB J.Hilk 2 Replies Last reply Reply Quote 0
      • JonB
        JonB @rezaMSLM last edited by

        @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 Reply Quote 3
        • J.Hilk
          J.Hilk Moderators @rezaMSLM last edited by 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.

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

          Qt Needs YOUR vote: https://bugreports.qt.io/browse/QTQAINFRA-4121


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

          R 1 Reply Last reply Reply Quote 5
          • R
            rezaMSLM @J.Hilk last edited by

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

            J.Hilk 1 Reply Last reply Reply Quote 0
            • J.Hilk
              J.Hilk Moderators @rezaMSLM last edited by J.Hilk

              @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

              Qt Needs YOUR vote: https://bugreports.qt.io/browse/QTQAINFRA-4121


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

              1 Reply Last reply Reply Quote 3
              • First post
                Last post