做者:zzssdd2html
E-mail:[email protected]++
1、前言
开发环境:Qt5.12.10 + MinGWapp
实现的功能socket
串口数据的接收
ascii字符形式显示与hex字符形式显示
时间戳的显示
接收数据的统计与显示
接收清零
涉及的知识点ide
QSerialPort类的使用
数据格式的转换
QTime类的使用
控件QTextEdit、QCheckBox、QPushButton、QLabel的使用
2、功能实现
下面开始逐步讲解以上列举的功能实现函数
2.一、数据读取
在《QT串口助手(二):参数配置》中已经实现了串口参数的配置,参数配置完成后就能够开启串口的数据接收功能了。在QT中的QSerialPort类继承自QIODevice类,因此能够使用QIODevice的readyRead()信号来触发数据的接收,在槽函数中实现数据的读取与处理。信号槽链接以下:oop
/* 接收数据信号槽 */
connect(serial, &QSerialPort::readyRead, this, &Widget::SerialPortReadyRead_slot);
补充:ui
[signal]void QIODevice::readyRead()
This signal is emitted once every time new data is available for reading from the device's current read channel. It will only be emitted again once new data is available, such as when a new payload of network data has arrived on your network socket, or when a new block of data has been appended to your device.this
readyRead() is not emitted recursively; if you reenter the event loop or call waitForReadyRead() inside a slot connected to the readyRead() signal, the signal will not be reemitted (although waitForReadyRead() may still return true).spa
Note for developers implementing classes derived from QIODevice: you should always emit readyRead() when new data has arrived (do not emit it only because there's data still to be re