QBluetoothServer Class
QBluetoothServer 클래스는 RFCOMM 또는 L2cap 프로토콜을 사용하여 블루투스 장치와 통신합니다. 더 보기...
Header: | #include <QBluetoothServer> |
qmake: | QT += bluetooth |
Inherits: | QObject |
공용 유형
enum | Error { NoError, UnknownError, PoweredOffError, InputOutputError, ServiceAlreadyRegisteredError, …, MissingPermissionsError } |
공용 함수
QBluetoothServer(QBluetoothServiceInfo::Protocol serverType, QObject *parent = nullptr) | |
virtual | ~QBluetoothServer() |
void | close() |
QBluetoothServer::Error | error() const |
bool | hasPendingConnections() const |
bool | isListening() const |
bool | listen(const QBluetoothAddress &address = QBluetoothAddress(), quint16 port = 0) |
QBluetoothServiceInfo | listen(const QBluetoothUuid &uuid, const QString &serviceName = QString()) |
int | maxPendingConnections() const |
QBluetoothSocket * | nextPendingConnection() |
QBluetooth::SecurityFlags | securityFlags() const |
QBluetoothAddress | serverAddress() const |
quint16 | serverPort() const |
QBluetoothServiceInfo::Protocol | serverType() const |
void | setMaxPendingConnections(int numConnections) |
void | setSecurityFlags(QBluetooth::SecurityFlags security) |
Signals
(since 6.2) void | errorOccurred(QBluetoothServer::Error error) |
void | newConnection() |
상세 설명
QBluetoothServer는 RFCOMM 또는 L2cap을 통해 블루투스 서비스를 구현하는 데 사용됩니다.
listen()로 들어오는 연결을 수신 대기하기 시작합니다. 새 연결이 설정되면 newConnection() 신호가 전송될 때까지 기다렸다가 nextPendingConnection()를 호출하여 새 연결에 대한 QBluetoothSocket 을 받습니다.
다른 디바이스에서 서비스를 찾을 수 있도록 하려면 서비스에 해당하는 속성으로 QBluetoothServiceInfo 을 만들고 QBluetoothServiceInfo::registerService()을 사용하여 등록합니다. serverPort ()를 호출하여 사용 중인 채널 번호를 알아냅니다.
플랫폼에서 QBluetoothServiceInfo::Protocol 을 지원하지 않는 경우 listen()은 false
을 반환합니다. 예를 들어 Android와 WinRT는 RFCOMM만 지원합니다.
iOS에서는 플랫폼이 QBluetoothServer 관련 기능에 액세스할 수 있는 API를 노출하지 않기 때문에 이 클래스를 사용할 수 없습니다.
QBluetoothServiceInfo 및 QBluetoothSocket 을참조하세요 .
멤버 유형 문서
enum QBluetoothServer::Error
이 열거형은 Bluetooth 서버 오류 유형을 설명합니다.
상수 | 값 | 설명 |
---|---|---|
QBluetoothServer::NoError | 0 | 오류가 없습니다. |
QBluetoothServer::UnknownError | 1 | 알 수 없는 오류가 발생했습니다. |
QBluetoothServer::PoweredOffError | 2 | 블루투스 어댑터의 전원이 꺼져 있습니다. |
QBluetoothServer::InputOutputError | 3 | 입력 출력 오류가 발생했습니다. |
QBluetoothServer::ServiceAlreadyRegisteredError | 4 | 서비스 또는 포트가 이미 등록되었습니다. |
QBluetoothServer::UnsupportedProtocolError | 5 | Protocol 은 이 플랫폼에서 지원되지 않습니다. |
QBluetoothServer::MissingPermissionsError (since Qt 6.4) | 6 | 운영 체제에서 사용자가 부여하지 않은 권한을 요청합니다. |
멤버 기능 문서
[explicit]
QBluetoothServer::QBluetoothServer(QBluetoothServiceInfo::Protocol serverType, QObject *parent = nullptr)
parent 및 serverType 으로 블루투스 서버를 구축합니다.
[virtual noexcept]
QBluetoothServer::~QBluetoothServer()
블루투스 서버를 파괴합니다.
void QBluetoothServer::close()
수신 소켓을 닫고 초기화합니다. 이미 설정된 QBluetoothSocket 은 계속 작동하며 별도로 closed 을 설정해야 합니다.
QBluetoothServer::Error QBluetoothServer::error() const
QBluetoothServer 의 마지막 오류를 반환합니다.
[signal, since 6.2]
void QBluetoothServer::errorOccurred(QBluetoothServer::Error error)
이 신호는 error 발생 시 방출됩니다.
이 함수는 Qt 6.2에 도입되었습니다.
error() 및 QBluetoothServer::Error 을참조하십시오 .
bool QBluetoothServer::hasPendingConnections() const
연결이 보류 중이면 참을 반환하고, 그렇지 않으면 거짓을 반환합니다.
bool QBluetoothServer::isListening() const
서버가 들어오는 연결을 수신 대기 중이면 true를 반환하고, 그렇지 않으면 false를 반환합니다.
bool QBluetoothServer::listen(const QBluetoothAddress &address = QBluetoothAddress(), quint16 port = 0)
port 에서 address 로 들어오는 연결을 수신 대기하기 시작합니다. address 은 로컬 Bluetooth 어댑터 주소여야 하며 port 은 0보다 커야 하고 다른 Bluetooth 서버 객체가 이미 사용하고 있지 않아야 합니다. 시스템이 자동으로 포트를 선택할 수 있도록 포트 번호를 설정하지 않는 것이 좋습니다.
작업이 성공하고 서버가 들어오는 연결을 수신 대기 중이면 true
을 반환하고, 그렇지 않으면 false
을 반환합니다.
서버 객체가 이미 들어오는 연결을 수신 대기 중이면 이 함수는 항상 false
을 반환합니다. close()을 호출하기 전에 이 함수를 호출해야 합니다.
isListening() 및 newConnection()도 참조하세요 .
QBluetoothServiceInfo QBluetoothServer::listen(const QBluetoothUuid &uuid, const QString &serviceName = QString())
uuid 및 serviceName 에 SPP 서비스를 등록하기 위한 편의 함수입니다. 이 함수는 이미 서비스를 등록했기 때문에 반환되는 QBluetoothServiceInfo 객체는 더 이상 변경할 수 없습니다. 나중에 서버를 종료하려면 이 서버 객체에서 QBluetoothServiceInfo::unregisterService() 및 close()를 호출해야 합니다.
성공하면 등록된 QBluetoothServiceInfo 인스턴스를 반환하고, 그렇지 않으면 잘못된 QBluetoothServiceInfo 을 반환합니다. 이 함수는 항상 기본 블루투스 어댑터를 사용해야 한다고 가정합니다.
서버 객체가 이미 수신 연결을 수신 대기 중이면 이 함수는 잘못된 QBluetoothServiceInfo 을 반환합니다.
RFCOMM 서버의 경우 이 함수는 다음 코드 스니펫과 동일합니다.
QBluetoothServiceInfo serviceInfo; serviceInfo.setAttribute(QBluetoothServiceInfo::ServiceName, serviceName); QBluetoothServiceInfo::Sequence browseSequence; browseSequence << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::ServiceClassUuid::PublicBrowseGroup)); serviceInfo.setAttribute(QBluetoothServiceInfo::BrowseGroupList, browseSequence); QBluetoothServiceInfo::Sequence profileSequence; QBluetoothServiceInfo::Sequence classId; classId << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::ServiceClassUuid::SerialPort)); classId << QVariant::fromValue(quint16(0x100)); profileSequence.append(QVariant::fromValue(classId)); serviceInfo.setAttribute(QBluetoothServiceInfo::BluetoothProfileDescriptorList, profileSequence); classId.clear(); //Android requires custom uuid to be set as service class classId << QVariant::fromValue(uuid); classId << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::ServiceClassUuid::SerialPort)); serviceInfo.setAttribute(QBluetoothServiceInfo::ServiceClassIds, classId); serviceInfo.setServiceUuid(uuid); QBluetoothServiceInfo::Sequence protocolDescriptorList; QBluetoothServiceInfo::Sequence protocol; protocol << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::ProtocolUuid::L2cap)); if (d->serverType == QBluetoothServiceInfo::L2capProtocol) protocol << QVariant::fromValue(serverPort()); protocolDescriptorList.append(QVariant::fromValue(protocol)); protocol.clear(); protocol << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::ProtocolUuid::Rfcomm)) << QVariant::fromValue(quint8(serverPort())); protocolDescriptorList.append(QVariant::fromValue(protocol)); serviceInfo.setAttribute(QBluetoothServiceInfo::ProtocolDescriptorList, protocolDescriptorList); bool result = serviceInfo.registerService();
isListening(), newConnection() 및 listen()도 참조하세요 .
int QBluetoothServer::maxPendingConnections() const
보류 중인 최대 연결 수를 반환합니다.
setMaxPendingConnections()도 참조하세요 .
[signal]
void QBluetoothServer::newConnection()
이 신호는 새 연결을 사용할 수 있을 때 발생합니다.
연결된 슬롯은 nextPendingConnection()를 호출하여 연결을 통해 데이터를 주고받을 QBluetoothSocket 객체를 가져와야 합니다.
nextPendingConnection() 및 hasPendingConnections()도 참조하세요 .
QBluetoothSocket *QBluetoothServer::nextPendingConnection()
다음 대기 중인 연결에 대한 QBluetoothSocket 포인터를 반환합니다. 포인터를 삭제하는 것은 호출자의 책임입니다.
QBluetooth::SecurityFlags QBluetoothServer::securityFlags() const
블루투스 보안 플래그를 반환합니다.
setSecurityFlags()도 참조하세요 .
QBluetoothAddress QBluetoothServer::serverAddress() const
서버 주소를 반환합니다.
quint16 QBluetoothServer::serverPort() const
서버 포트 번호를 반환합니다.
QBluetoothServiceInfo::Protocol QBluetoothServer::serverType() const
QBluetoothServer 의 유형을 반환합니다.
void QBluetoothServer::setMaxPendingConnections(int numConnections)
대기 중인 연결의 최대 수를 numConnections 으로 설정합니다. 대기 중인 소켓 수가 이 제한을 초과하면 새 소켓이 거부됩니다.
maxPendingConnections()도 참조하세요 .
void QBluetoothServer::setSecurityFlags(QBluetooth::SecurityFlags security)
블루투스 보안 플래그를 security 로 설정합니다. 이 함수는 listen()를 호출하기 전에 호출해야 합니다. 블루투스 2.1 장치를 사용할 때는 암호화가 필수이므로 블루투스 링크가 항상 암호화됩니다.
Android는 두 가지 보안 수준(보안 및 비보안)만 지원합니다. 이 플래그를 QBluetooth::Security::NoSecurity 로 설정하면 서버 객체는 인증이나 암호화를 사용하지 않습니다. 다른 보안 플래그 조합은 보안 블루투스 연결을 트리거합니다.
macOS에서는 보안 플래그가 지원되지 않으며 무시됩니다.
securityFlags()도 참조하세요 .
© 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.