qt 如何判断串口是否存在
1、Qt很容易扩展,并且允许真正地组件编程,它既可以开发GUI程序,也可用于开发非GUI程序,比如控制台工具和服务器。基本上,Qt 同 X Window 上的 Motif,Openw足毂忍珩in,GTK 等图形界 面库和 Windows 平台上的 MFC,OWL,VCL,ATL 是同类型的东西。

3、至为关键的是,Qt 包括多达 250 个以上的 C++ 类,还提供基于模板的 collections, serialization, file, I/O device, directory management, date/time 类,甚至还包括正则表达式的处理功能。

5、在QSerialPortInfo类中,方法availablePorts()表示检测到的串口中可用的串口,使用此方法就可以判断串口是否存在了。在使用时,需要在头文件中包含如下语句:#include <QtSerialPort/QSerialPortInfo>

6、检查串口是否存在的示例代码如下:foreach (const QSerialPortInfo &in熠硒勘唏fo, QSerialPortInfo::availablePorts()) { QString s = QObject::tr("Port: ") + info.portName() + "\n" + QObject::tr("Location: ") + info.systemLocation() + "\n" + QObject::tr("Description: ") + info.description() + "\n" + QObject::tr("Manufacturer: ") + info.manufacturer() + "\n" + QObject::tr("Serial number: ") + info.serialNumber() + "\n" + QObject::tr("Vendor Identifier: ") + (info.hasVendorIdentifier() ? QString::number(info.vendorIdentifier(), 16) : QString()) + "\n" + QObject::tr("Product Identifier: ") + (info.hasProductIdentifier() ? QString::number(info.productIdentifier(), 16) : QString()) + "\n" + QObject::tr("Busy: ") + (info.isBusy() ? QObject::tr("Yes") : QObject::tr("No")) + "\n"; }
