QSerialPortInfo 类

提供有关现有串行端口的信息。 更多...

头: #include <QSerialPortInfo>
CMake: find_package(Qt6 REQUIRED COMPONENTS SerialPort)
target_link_libraries(mytarget PRIVATE Qt6::SerialPort)
qmake: QT += serialport

公共函数

QSerialPortInfo ()
QSerialPortInfo (const QSerialPort & port )
QSerialPortInfo (const QString & name )
QSerialPortInfo (const QSerialPortInfo & other )
~QSerialPortInfo ()
QString description () const
bool hasProductIdentifier () const
bool hasVendorIdentifier () const
bool isNull () const
QString manufacturer () const
QString portName () const
quint16 productIdentifier () const
QString serialNumber () const
void swap (QSerialPortInfo & other )
QString systemLocation () const
quint16 vendorIdentifier () const
QSerialPortInfo & operator= (const QSerialPortInfo & other )

静态公共成员

QList<QSerialPortInfo> availablePorts ()
QList<qint32> standardBaudRates ()

详细描述

Use the static availablePorts () function to generate a list of QSerialPortInfo objects. Each QSerialPortInfo object in the list represents a single serial port and can be queried for the port name , system location , description , manufacturer , and some other hardware parameters. The QSerialPortInfo class can also be used as an input parameter for the setPort () method of the QSerialPort 类。

用法范例

The example code enumerates all available serial ports and prints their parameters to console:

    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());
    }
					

另请参阅 QSerialPort .

成员函数文档编制

QSerialPortInfo:: QSerialPortInfo ()

构造空的 QSerialPortInfo 对象。

另请参阅 isNull ().

[explicit] QSerialPortInfo:: QSerialPortInfo (const QSerialPort & port )

构造 QSerialPortInfo 对象从串行 port .

[explicit] QSerialPortInfo:: QSerialPortInfo (const QString & name )

构造 QSerialPortInfo 对象从串行端口 name .

This constructor finds the relevant serial port among the available ones according to the port name name , and constructs the serial port info instance for that port.

QSerialPortInfo:: QSerialPortInfo (const QSerialPortInfo & other )

构造副本为 other .

[noexcept] QSerialPortInfo:: ~QSerialPortInfo ()

销毁 QSerialPortInfo object. References to the values in the object become invalid.

[static] QList < QSerialPortInfo > QSerialPortInfo:: availablePorts ()

返回系统可用串行端口的列表。

QString QSerialPortInfo:: description () const

Returns the description string of the serial port, if available; otherwise returns an empty string.

另请参阅 manufacturer () 和 serialNumber ().

bool QSerialPortInfo:: hasProductIdentifier () const

返回 true 若存在有效 16-bit 产品编号呈现;否则返回 false .

另请参阅 productIdentifier (), vendorIdentifier (),和 hasVendorIdentifier ().

bool QSerialPortInfo:: hasVendorIdentifier () const

返回 true 若存在有效 16-bit vendor number present; otherwise returns false .

另请参阅 vendorIdentifier (), productIdentifier (),和 hasProductIdentifier ().

bool QSerialPortInfo:: isNull () const

Returns whether this QSerialPortInfo object holds a serial port definition.

QString QSerialPortInfo:: manufacturer () const

Returns the manufacturer string of the serial port, if available; otherwise returns an empty string.

另请参阅 description () 和 serialNumber ().

QString QSerialPortInfo:: portName () const

返回串行端口的名称。

另请参阅 systemLocation ().

quint16 QSerialPortInfo:: productIdentifier () const

Returns the 16-bit product number for the serial port, if available; otherwise returns zero.

另请参阅 hasProductIdentifier (), vendorIdentifier (),和 hasVendorIdentifier ().

QString QSerialPortInfo:: serialNumber () const

返回串行端口的序列号字符串,若可用;否则返回空字符串。

注意: 序列号可能包含字母。

另请参阅 description () 和 manufacturer ().

[static] QList < qint32 > QSerialPortInfo:: standardBaudRates ()

Returns a list of available standard baud rates supported by the target platform.

void QSerialPortInfo:: swap ( QSerialPortInfo & other )

交换 QSerialPortInfo other with this QSerialPortInfo 。此操作非常快且从不失败。

QString QSerialPortInfo:: systemLocation () const

Returns the system location of the serial port.

另请参阅 portName ().

quint16 QSerialPortInfo:: vendorIdentifier () const

Returns the 16-bit vendor number for the serial port, if available; otherwise returns zero.

另请参阅 hasVendorIdentifier (), productIdentifier (),和 hasProductIdentifier ().

QSerialPortInfo &QSerialPortInfo:: operator= (const QSerialPortInfo & other )

设置 QSerialPortInfo 对象等于 other .