このページでは

QSerialPortInfo Class

既存のシリアルポートに関する情報を表示します。詳細...

ヘッダー: #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()

詳細な説明

静的関数availablePorts() を使用して、QSerialPortInfo オブジェクトのリストを生成します。リスト内の各 QSerialPortInfo オブジェクトは 1 つのシリアルポートを表しており、port name 、system location 、description 、manufacturer 、およびその他のハードウェアパラメータを照会することができます。また、QSerialPortInfo クラスは、QSerialPort クラスのsetPort() メソッドの入力パラメータとしても使用できます。

使用例

以下のサンプルコードは、利用可能なすべてのシリアルポートを列挙し、そのパラメータをコンソールに出力します:

   const autoserialPortInfos=QSerialPortInfo::availablePorts();
    for(constQSerialPortInfo&portInfo: serialPortInfos) {
        qDebug() << "\n"
                << "ポート:" <<portInfo.portName()<< "\n"
                 << "場所:" <<portInfo.systemLocation()<< "\n"
                 << "説明:" <<portInfo.description()<< "\n"
                << "メーカー:" <<portInfo.manufacturer()<< "\n"
                 << "シリアル番号:" <<portInfo.serialNumber()<< "\n"
                 << "ベンダー識別子:"
                <<(portInfo.hasVendorIdentifier()
                     ?QByteArray::number(portInfo.vendorIdentifier(), 16)
                     : QByteArray())<< "\n"
                 << "製品識別子:"
                 <<(portInfo.hasProductIdentifier()
                     ?QByteArray::number(portInfo.productIdentifier(), 16)
                     : QByteArray());
    }

Linux でのポート列挙

デフォルトでは、Linuxはlibudev を使用して利用可能なシリアルポートを列挙します。このライブラリが利用できない場合は、/sys/class/tty ディレクトリ内のファイルを読み込むように切り替わります。

一部のバージョンのlibudev にはバグがあり、実際のデバイスではなく USB ハブの VID および PID を誤って報告することが知られています。そのような場合は、環境変数QT_SERIALPORT_SKIP_UDEV_LOOKUP を定義してlibudev の検索をスキップし、/sys/class/tty ディレクトリの情報のみを使用するようにしてください。

QSerialPortも参照してください 。

メンバ関数のドキュメント

QSerialPortInfo::QSerialPortInfo()

空の QSerialPortInfo オブジェクトを作成します。

isNull()も参照してください 。

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

シリアルport からQSerialPortInfoオブジェクトを生成します。

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

シリアルポート「name 」から QSerialPortInfo オブジェクトを生成します。

このコンストラクタは、ポート名 `name` に基づいて、利用可能なシリアルポートの中から該当するポートを検索し、そのポートのシリアルポート情報インスタンスを作成します。

QSerialPortInfo::QSerialPortInfo(const QSerialPortInfo &other)

other のコピーを作成します。

[noexcept] QSerialPortInfo::~QSerialPortInfo()

QSerialPortInfo オブジェクトを破棄します。このオブジェクト内の値への参照は無効になります。

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

システム上で利用可能なシリアルポートのリストを返します。

Port enumeration on Linuxも参照してください 。

QString QSerialPortInfo::description() const

シリアルポートの説明文字列が存在する場合はそれを返し、存在しない場合は空の文字列を返します。

manufacturer() およびserialNumber()も参照してください 。

bool QSerialPortInfo::hasProductIdentifier() const

有効な16-bit 製品番号が存在する場合はtrue を返し、そうでない場合はfalse を返します。

productIdentifier()、vendorIdentifier()、およびhasVendorIdentifier()も参照してください 。

bool QSerialPortInfo::hasVendorIdentifier() const

有効な16-bit ベンダー番号が存在する場合はtrue を返し、そうでない場合はfalse を返します。

vendorIdentifier()、productIdentifier()、およびhasProductIdentifier()も参照してください 。

bool QSerialPortInfo::isNull() const

このQSerialPortInfo オブジェクトがシリアルポートの定義を保持しているかどうかを返します。

QString QSerialPortInfo::manufacturer() const

シリアルポートのメーカー名文字列が存在する場合はそれを返し、存在しない場合は空の文字列を返します。

description() およびserialNumber()も参照してください 。

QString QSerialPortInfo::portName() const

シリアルポートの名前を返します。

systemLocation()も参照してください 。

quint16 QSerialPortInfo::productIdentifier() const

利用可能な場合は、シリアルポートの16ビットの製品番号を返します。利用できない場合は0を返します。

hasProductIdentifier()、vendorIdentifier()、およびhasVendorIdentifier()も参照してください 。

QString QSerialPortInfo::serialNumber() const

シリアルポートのシリアル番号文字列が存在する場合はそれを返し、存在しない場合は空の文字列を返します。

注: シリアル番号には 英字が含まれる場合があります。

関連項目: description() およびmanufacturer()。

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

ターゲットプラットフォームでサポートされている利用可能な標準ボーレートのリストを返します。

void QSerialPortInfo::swap(QSerialPortInfo &other)

QSerialPortInfo other をQSerialPortInfo に置き換えます。この処理は非常に高速で、失敗することはありません。

QString QSerialPortInfo::systemLocation() const

シリアルポートのシステム上の位置を返します。

portName()も参照してください 。

quint16 QSerialPortInfo::vendorIdentifier() const

シリアルポートの16ビットベンダー番号が存在する場合はそれを返し、存在しない場合は0を返します。

hasVendorIdentifier()、productIdentifier()、およびhasProductIdentifier()も参照してください 。

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

QSerialPortInfo オブジェクトをother と同じ値に設定します。

© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.