首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Qt官方示例-枚举器

Qt官方示例-枚举器

作者头像
Qt君
发布2020-04-01 11:18:38
5830
发布2020-04-01 11:18:38
举报
文章被收录于专栏:跟Qt君学编程跟Qt君学编程

❝该示例演示如何显示系统中串行设备的信息。 ❞

  此GUI示例在类QSerialPortInfo中提供有关小部件中的串行端口的信息。要获取有关可用端口的信息,请使用静态方法availablePorts()

  示例源码:

#include <QLabel>
#include <QScrollArea>
#include <QSerialPortInfo>
#include <QVBoxLayout>
#include <QWidget>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    auto layout = new QVBoxLayout;

    const auto infos = QSerialPortInfo::availablePorts();
    for (const QSerialPortInfo &info : infos) {
        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";

        auto label = new QLabel(s);
        layout->addWidget(label);
    }

    auto workPage = new QWidget;
    workPage->setLayout(layout);

    QScrollArea area;
    area.setWindowTitle(QObject::tr("Info about all available serial ports."));
    area.setWidget(workPage);
    area.show();

    return a.exec();
}

关于更多

  • 「QtCreator软件」可以找到:
  • 或在以下「Qt安装目录」找到:
C:\Qt\{你的Qt版本}\Examples\{你的Qt版本}\serialport\enumerator
  • 「相关链接」
https://doc.qt.io/qt-5/qtserialport-enumerator-example.html
本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2020-03-22,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 Qt君 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 关于更多
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档