QSerialPortInfo Class
The QSerialPortInfo class describes a serial port on the system. More…
| Header | #include <QSerialPortInfo> |
|---|---|
| CMake | target_link_libraries(app PRIVATE Nt::SerialPort) |
| Module | Nt Serial Port C++ Classes |
| Since | 6.0 |
List of all members, including inherited members
Public Functions
| QSerialPortInfo() | |
| QSerialPortInfo(const QSerialPort &port) | |
| QSerialPortInfo(const QString &name) | |
| void | swap(QSerialPortInfo &other) |
| QString | portName() const |
| QString | systemLocation() const |
| QString | description() const |
| QString | manufacturer() const |
| QString | serialNumber() const |
| quint16 | vendorIdentifier() const |
| quint16 | productIdentifier() const |
| bool | hasVendorIdentifier() const |
| bool | hasProductIdentifier() const |
| bool | isNull() const |
Static Public Members
| QList<qint32> | standardBaudRates() |
| QList<QSerialPortInfo> | availablePorts() |
Detailed Description
availablePorts() lists the ports of the machine. Each entry gives the name of the port, which can be passed to QSerialPort, and what is known about the hardware behind it:
const QList<QSerialPortInfo> ports = QSerialPortInfo::availablePorts();
for (const QSerialPortInfo &info : ports) {
qDebug() << info.portName() << info.description();
if (info.hasVendorIdentifier())
qDebug() << "USB vendor" << info.vendorIdentifier();
}
See also QSerialPort.
Differences from Qt
Ports are found through sysfs, so availablePorts() returns nothing on other systems, and only USB and PCI hardware reports identifiers. Pseudo terminals are not listed, because they have no entry in sysfs. Objects of this class are plain values, not implicitly shared.
Member Function Documentation
QSerialPortInfo::QSerialPortInfo()
Constructs a null object.
See also isNull().
QSerialPortInfo::QSerialPortInfo(const QSerialPort &port)
Constructs an object describing the same port as port. The object is null if the port is not one of availablePorts().
See also isNull().
QSerialPortInfo::QSerialPortInfo(const QString &name)
Constructs an object describing the port called name, as returned by portName(). The object is null if no such port is in availablePorts().
See also isNull().
QList<QSerialPortInfo> QSerialPortInfo::availablePorts()
Returns the serial ports of the machine, sorted by name.
QString QSerialPortInfo::description() const
Returns the description of the hardware, or an empty string if it has none. For a USB device this is its product string.
bool QSerialPortInfo::hasProductIdentifier() const
Returns true if the port has a product identifier; otherwise returns false.
See also productIdentifier().
bool QSerialPortInfo::hasVendorIdentifier() const
Returns true if the port has a vendor identifier; otherwise returns false.
See also vendorIdentifier().
bool QSerialPortInfo::isNull() const
Returns true if the object does not describe a port; otherwise returns false.
QString QSerialPortInfo::manufacturer() const
Returns the manufacturer of the hardware, or an empty string if it is not known.
QString QSerialPortInfo::portName() const
Returns the name of the port, such as ttyUSB0.
See also systemLocation().
quint16 QSerialPortInfo::productIdentifier() const
Returns the product identifier, or 0 if there is none.
See also hasProductIdentifier().
QString QSerialPortInfo::serialNumber() const
Returns the serial number of the hardware, or an empty string if it has none.
QList<qint32> QSerialPortInfo::standardBaudRates()
Returns the baud rates the system has a named constant for. Other rates may still work; see QSerialPort::setBaudRate().
void QSerialPortInfo::swap(QSerialPortInfo &other)
Swaps this object with other.
QString QSerialPortInfo::systemLocation() const
Returns the path of the device node, such as /dev/ttyUSB0.
See also portName().
quint16 QSerialPortInfo::vendorIdentifier() const
Returns the vendor identifier, or 0 if there is none.
See also hasVendorIdentifier().