QSerialPortInfo

Provides information about existing serial ports.

Declared in src/libs/libserial/serial/SerialPortInfo.hpp
Group serialport-main

Detailed description

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 class.

Example Usage

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

Port enumeration on Linux

By default Linux uses libudev to enumerate the available serial ports. If the library is not available, it falls back to reading files in the /sys/class/tty directory.

It is known that some versions of libudev have a bug and incorrectly report VID and PID of a USB hub instead of the actual device. In such cases, define the QT_SERIALPORT_SKIP_UDEV_LOOKUP environment variable to skip the libudev lookup and only use the information from the /sys/class/tty directory.

See also QSerialPort.

Member function documentation

QSerialPortInfo

QSerialPortInfo::QSerialPortInfo()

Constructs an empty QSerialPortInfo object.

See also isNull().

QSerialPortInfo (2)

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

Constructs a QSerialPortInfo object from serial port.

QSerialPortInfo (4)

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

Constructs a QSerialPortInfo object from serial port 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 (3)

QSerialPortInfo::QSerialPortInfo(const QSerialPortInfo &other)

Constructs a copy of other.

dtor.QSerialPortInfo

[noexcept] QSerialPortInfo::~QSerialPortInfo()

Destroys the QSerialPortInfo object. References to the values in the object become invalid.

availablePorts

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

Returns a list of available serial ports on the system.

See also Port enumeration on Linux.

description

QString QSerialPortInfo::description() const

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

See also manufacturer(), serialNumber().

hasProductIdentifier

bool QSerialPortInfo::hasProductIdentifier() const

Returns true if there is a valid 16-bit product number present; otherwise returns false.

See also productIdentifier(), vendorIdentifier(), hasVendorIdentifier().

hasVendorIdentifier

bool QSerialPortInfo::hasVendorIdentifier() const

Returns true if there is a valid 16-bit vendor number present; otherwise returns false.

See also vendorIdentifier(), productIdentifier(), hasProductIdentifier().

isNull

bool QSerialPortInfo::isNull() const

Returns whether this QSerialPortInfo object holds a serial port definition.

manufacturer

QString QSerialPortInfo::manufacturer() const

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

See also description(), serialNumber().

portName

QString QSerialPortInfo::portName() const

Returns the name of the serial port.

See also systemLocation().

productIdentifier

quint16 QSerialPortInfo::productIdentifier() const

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

See also hasProductIdentifier(), vendorIdentifier(), hasVendorIdentifier().

serialNumber

[since 5.3] QString QSerialPortInfo::serialNumber() const

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

Note: The serial number may include letters.

This function was introduced in 5.3.

See also description(), manufacturer().

standardBaudRates

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

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

swap

void QSerialPortInfo::swap(QSerialPortInfo &other)

Swaps QSerialPortInfo other with this QSerialPortInfo. This operation is very fast and never fails.

systemLocation

QString QSerialPortInfo::systemLocation() const

Returns the system location of the serial port.

See also portName().

vendorIdentifier

quint16 QSerialPortInfo::vendorIdentifier() const

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

See also hasVendorIdentifier(), productIdentifier(), hasProductIdentifier().

operator-eq

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

Sets the QSerialPortInfo object to be equal to other.

In this section