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 namesystem locationdescriptionmanufacturer 、その他いくつかのハードウェア・パラメータを問い合わせることができます。QSerialPortInfoクラスは、QSerialPort クラスのsetPort ()メソッドの入力パラメータとしても使用できます。

使用例

このサンプル・コードは、利用可能なすべてのシリアル・ポートを列挙し、それらのパラメータをコンソールに表示します:

   const autoserialPortInfos=QSerialPortInfo::availablePorts();for(constQSerialPortInfo&portInfo: serialPortInfos) { 以下のようになります。        qDebug() << "\n"
                << "Port:"<<portInfo.portName()<< "ⅳn"<< "Location:"<<portInfo.systemLocation()<< "ⅳn"<< "Description:"<<portInfo.description()<< "ⅳn"<< "Manufacturer:"<<portInfo.製造元:"<< "製造番号:"<<portInfo.serialNumber()<< " シリアル番号 : "<<portInfo.hasVendorIdentifier()?QByteArray::number(portInfo.vendorIdentifier(), 16) : QByteArray())<< " 商品識別子:"<<(portInfo.hasProductIdentifier()?QByteArray::number(portInfo.productIdentifier(), 16) : QByteArray()); }

Linuxでのポート列挙

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

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

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 ビットの製品番号があればそれを返す。

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 ビットのベンダー番号を返す。

hasVendorIdentifier()、productIdentifier()、hasProductIdentifier()も参照のこと

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

QSerialPortInfo オブジェクトをother と等しくなるように設定する。

© 2025 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.