In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly explains "how to realize Qt5 serial port class QSerialPort". The explanation content in this article is simple and clear, easy to learn and understand. Please follow the idea of Xiaobian slowly and deeply to study and learn "how to realize Qt5 serial port class QSerialPort" together.
brief description of
QtSerialPort module is provided above Qt5, which is convenient for programmers to quickly develop and apply serial port applications.
The QtSerialPort module provides two C++ classes, QSerialPort and QSerialPortInfo.
QSerialPort class is a serial port class encapsulated by Qt5, which can communicate with serial ports and provide various interfaces for operating serial ports.
The QSerialPortInfo class is an auxiliary class that provides information about the serial ports available on your computer. For example, serial port name, description, manufacturer, serial number, serial port 16-digit product number, etc. are available. Using the available serial port information provided by QSerialPortInfo, you can set the serial port baud rate and open the required serial port for communication.
The general steps of using Qt5 for serial communication are: Configure serial port parameters-> Open serial port-> Receive and receive data.
To use the QtSerialPort module, you need to add statements to the project file.pro file or.pri:
QT += serialport
Qt Version: 5.12.8
1. QSerialPortInfo class
List all serial devices on your computer. The Cpp file is as follows:
#include #include #include #include int main(int argc, char *argv[]){ QCoreApplication a(argc, argv); foreach (const QSerialPortInfo &info, QSerialPortInfo::availablePorts()) { qDebug() m_SerialPort->readAll()); while (this->m_SerialPort->waitForReadyRead(5)) readData.append(this->m_SerialPort->readAll()); if(readData.isEmpty()) return QByteArray();// qDebug() clear(); m_SerialPort->close();} Thank you for reading, the above is the content of "Qt5 serial class QSerialPort how to achieve", after learning this article, I believe everyone on Qt5 serial class QSerialPort how to achieve this problem has a deeper understanding, the specific use of the situation also needs to be verified by practice. Here is, Xiaobian will push more articles related to knowledge points for everyone, welcome to pay attention!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.