Have trouble while using QSerialPort in QT5.13.1 and win10
-
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 -
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
-
@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).
-
@alphasion So please mark this topic as SOLVED too. Thanks!