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. Have trouble while using QSerialPort in QT5.13.1 and win10
Forum Updated to NodeBB v4.3 + New Features

Have trouble while using QSerialPort in QT5.13.1 and win10

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 4 Posters 755 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.
  • A Offline
    A Offline
    alphasion
    wrote on last edited by
    #1

    here is my sourse code:

    QList<QSerialPortInfo> infoList=QSerialPortInfo::availablePorts();
        if(infoList.count()>0)
        {
            port=new QSerialPort(infoList.at(0));
            port->setReadBufferSize(4096);
            connect(port,&QSerialPort::readyRead,this,&MainWindow::DataReady);
            port->open(QSerialPort::ReadWrite);
            while(true)
                qDebug()<<"Port Open"<<port->bytesAvailable();
        }
    

    i am plug a pixhawk flight control and it's keep sending data through USB serial port.
    but i can't get data from read,and port->bytesAvailable() is always zero,
    code seems nothing wrong ,but it's not working.
    could any one help on this problem?thanks a lot

    aha_1980A 1 Reply Last reply
    0
    • V Offline
      V Offline
      viniltc
      wrote on last edited by
      #2

      Hi
      Are you configuring it right? where are you setting baudrate, flow control etc?
      Also, I think connect is called once you open the serial port, right?

      A 1 Reply Last reply
      0
      • A alphasion

        here is my sourse code:

        QList<QSerialPortInfo> infoList=QSerialPortInfo::availablePorts();
            if(infoList.count()>0)
            {
                port=new QSerialPort(infoList.at(0));
                port->setReadBufferSize(4096);
                connect(port,&QSerialPort::readyRead,this,&MainWindow::DataReady);
                port->open(QSerialPort::ReadWrite);
                while(true)
                    qDebug()<<"Port Open"<<port->bytesAvailable();
            }
        

        i am plug a pixhawk flight control and it's keep sending data through USB serial port.
        but i can't get data from read,and port->bytesAvailable() is always zero,
        code seems nothing wrong ,but it's not working.
        could any one help on this problem?thanks a lot

        aha_1980A Offline
        aha_1980A Offline
        aha_1980
        Lifetime Qt Champion
        wrote on last edited by aha_1980
        #3

        Hi @alphasion,

        Qt 5.13.1 and 5.12.5 contains a bug in QtSerialPort on Windows with data receiving. You can search the forum for more info about this.

        Edit: but the while loop in your code looks wrong and will block the event loop!

        Regards

        Qt has to stay free or it will die.

        A 1 Reply Last reply
        3
        • V viniltc

          Hi
          Are you configuring it right? where are you setting baudrate, flow control etc?
          Also, I think connect is called once you open the serial port, right?

          A Offline
          A Offline
          alphasion
          wrote on last edited by
          #4

          @viniltc sure it's right,the code i pasted here didn't shown.
          it's working in C# with the same configurations.

          jsulmJ 1 Reply Last reply
          0
          • A alphasion

            @viniltc sure it's right,the code i pasted here didn't shown.
            it's working in C# with the same configurations.

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by jsulm
            #5

            @alphasion said in Have trouble while using QSerialPort in QT5.13.1 and win10:

            it's working in C# with the same configurations.

            C# is not Qt.
            In Qt you should never use endless loops in main thread as they will block the event loop and your application will stop responding. This is how event driven applications work.

            Please read QSerialPort documentation to see how to use the asynchronous API without blocking the event loop (especialy this signal: https://doc.qt.io/qt-5/qiodevice.html#readyRead).

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            2
            • aha_1980A aha_1980

              Hi @alphasion,

              Qt 5.13.1 and 5.12.5 contains a bug in QtSerialPort on Windows with data receiving. You can search the forum for more info about this.

              Edit: but the while loop in your code looks wrong and will block the event loop!

              Regards

              A Offline
              A Offline
              alphasion
              wrote on last edited by
              #6

              @aha_1980 Thanks it's fixed.

              aha_1980A 1 Reply Last reply
              1
              • A alphasion

                @aha_1980 Thanks it's fixed.

                aha_1980A Offline
                aha_1980A Offline
                aha_1980
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @alphasion So please mark this topic as SOLVED too. Thanks!

                Qt has to stay free or it will die.

                1 Reply Last reply
                1

                • Login

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