在ex2.pro 添加:
QT += serialport
//main.cpp
#include "ex2.h"
#include <QtSerialPort/QtSerialPort>
#include <QApplication>int main(int argc, char *argv[])
{QApplication a(argc, argv);Ex2 w;w.show();QList<QSerialPortInfo> list = QSerialPortInfo::availablePorts();qDebug() << "Total number of availiable ports:" << list.count();foreach(const QSerialPortInfo &serialportinfo, list){qDebug() << "===========================================";qDebug() << "Port: " << serialportinfo.portName();qDebug() << "Location: " << serialportinfo.systemLocation();qDebug() << "Description: " << serialportinfo.description();qDebug() << "Manufactutor: " << serialportinfo.manufacturer();qDebug() << "Vendor Indentifier: " << serialportinfo.vendorIdentifier();qDebug() << "Busy: " << serialportinfo.isBusy();}return a.exec();
}