summaryrefslogtreecommitdiff
path: root/src/serialport/doc/snippets/doc_src_serialport.cpp
blob: 11476c91fd6332b0a971555ad942ef5b07f9e03f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause

#include <QtCore/qcoreapplication.h>
#include <QtCore/qdebug.h>

#include <QtSerialPort/qserialportinfo.h>

void enumeratePorts()
{
//! [enumerate_ports]
    const auto serialPortInfos = QSerialPortInfo::availablePorts();
    for (const QSerialPortInfo &portInfo : serialPortInfos) {
        qDebug() << "\n"
                 << "Port:" << portInfo.portName() << "\n"
                 << "Location:" << portInfo.systemLocation() << "\n"
                 << "Description:" << portInfo.description() << "\n"
                 << "Manufacturer:" << portInfo.manufacturer() << "\n"
                 << "Serial number:" << portInfo.serialNumber() << "\n"
                 << "Vendor Identifier:"
                 << (portInfo.hasVendorIdentifier()
                     ? QByteArray::number(portInfo.vendorIdentifier(), 16)
                     : QByteArray()) << "\n"
                 << "Product Identifier:"
                 << (portInfo.hasProductIdentifier()
                     ? QByteArray::number(portInfo.productIdentifier(), 16)
                     : QByteArray());
    }
//! [enumerate_ports]
}

int main(int argc, char **argv)
{
    QCoreApplication app(argc, argv);

    enumeratePorts();

    return app.exec();
}

#include "doc_src_serialport.moc"