Qt C++ QSerialPortInfo的测试

此工程为一个基于命令行的Qt工程,所以只有以下两个文件

1、配置文件:

内容如下:

QT += gui
 
QT += serialport//测试必须要加这个,不然会报各种找不到匹配的函数的错误
 
CONFIG += c++11 console
CONFIG -= app_bundle
DEFINES += QT_DEPRECATED_WARNINGS
SOURCES += main.cpp

图片:

2、源文件:

main.cpp

#include <QCoreApplication>
#include <QDebug>
 
#include <QtSerialPort/QtSerialPort>
#include <QList>
 
int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    //实例化一个类型参数为QSerialPortInfo模板类链表
    QList<QSerialPortInfo> serialList;
    //给链表赋值为获取到的当前设备的所有串口信息的链表
    serialList = QSerialPortInfo::availablePorts();
    //输出链表头节点的一些信息
    qDebug()<< "Name : "<<serialList.first().portName();
    qDebug()<< "Description : "<<serialList.first().description();
    qDebug()<< "Manufacturer: "<<serialList.first().manufacturer();
    qDebug()<< "Serial Number: "<<serialList.first().serialNumber();
    qDebug()<< "System Location: "<<serialList.first().systemLocation();
 
    return a.exec();
}

图片

猜你喜欢

转载自www.cnblogs.com/tonifyingheart/p/9893561.html
今日推荐