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 객체는 단일 직렬 포트를 나타내며 port name, system location, description, manufacturer 및 기타 하드웨어 매개변수에 대해 쿼리할 수 있습니다. QSerialPortInfo 클래스는 QSerialPort 클래스의 setPort() 메서드에 대한 입력 매개변수로도 사용할 수 있습니다.

사용 예

예제 코드는 사용 가능한 모든 직렬 포트를 열거하고 해당 매개변수를 콘솔에 출력합니다:

   const auto serialPortInfos = QSerialPortInfo::availablePorts(); for(const QSerialPortInfo &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)

직렬에서 QSerialPortInfo 객체를 구축합니다 port.

[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 otherQSerialPortInfo 으로 바꿉니다. 이 작업은 매우 빠르며 실패하지 않습니다.

QString QSerialPortInfo::systemLocation() const

직렬 포트의 시스템 위치를 반환합니다.

portName()도 참조하세요 .

quint16 QSerialPortInfo::vendorIdentifier() const

사용 가능한 경우 직렬 포트의 16비트 공급업체 번호를 반환하고, 그렇지 않으면 0을 반환합니다.

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.