Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Reading from SerialPort and write to txt file.
Rika last edited by
I want to read data from COM port, then write to txt file and display them. But the data I received is incomplete. Here my code:
QByteArray datas = serialPort->readAll();
QMessageBox::warning(this, "Cảnh báo"+ file.errorString());
doc() is a function that displays file data.
@Rika readAll() will give you what currently is available (what was received so far). This code will not work as it is now. You either use a loop with waitForReadyRead(), read then and add the data to a buffer. Or you use signals slots to read when there is something to read. Also, how do you know that you got all the data? Do you have some protocol?
You should take a look at the examples: https://doc.qt.io/qt-5/qtserialport-examples.html