QBluetoothDeviceDiscoveryAgent Class

QBluetoothDeviceDiscoveryAgent 클래스는 주변의 블루투스 장치를 검색합니다. 더 보기...

Header: #include <QBluetoothDeviceDiscoveryAgent>
qmake: QT += bluetooth
Inherits: QObject

공개 유형

enum DiscoveryMethod { NoMethod, ClassicMethod, LowEnergyMethod }
flags DiscoveryMethods
enum Error { NoError, PoweredOffError, InputOutputError, InvalidBluetoothAdapterError, UnsupportedPlatformError, …, UnknownError }

공용 함수

QBluetoothDeviceDiscoveryAgent(QObject *parent = nullptr)
QBluetoothDeviceDiscoveryAgent(const QBluetoothAddress &deviceAdapter, QObject *parent = nullptr)
virtual ~QBluetoothDeviceDiscoveryAgent()
QList<QBluetoothDeviceInfo> discoveredDevices() const
QBluetoothDeviceDiscoveryAgent::Error error() const
QString errorString() const
bool isActive() const
int lowEnergyDiscoveryTimeout() const
void setLowEnergyDiscoveryTimeout(int timeout)

공용 슬롯

void start()
void start(QBluetoothDeviceDiscoveryAgent::DiscoveryMethods methods)
void stop()

신호

void canceled()
void deviceDiscovered(const QBluetoothDeviceInfo &info)
void deviceUpdated(const QBluetoothDeviceInfo &info, QBluetoothDeviceInfo::Fields updatedFields)
(since 6.2) void errorOccurred(QBluetoothDeviceDiscoveryAgent::Error error)
void finished()

정적 공개 멤버

QBluetoothDeviceDiscoveryAgent::DiscoveryMethods supportedDiscoveryMethods()

상세 설명

주변의 블루투스 장치를 검색합니다:

  • QBluetoothDeviceDiscoveryAgent의 인스턴스를 생성합니다,
  • deviceDiscovered() 또는 finished() 신호에 연결합니다,
  • start()를 호출합니다.
void MyClass::startDeviceDiscovery() { // 검색 에이전트를 생성하고 해당 신호에 연결합니다.   QBluetoothDeviceDiscoveryAgent *discoveryAgent = new QBluetoothDeviceDiscoveryAgent(this); connect(discoveryAgent, SIGNAL(deviceDiscovered(QBluetoothDeviceInfo)), this, SLOT(deviceDiscovered(QBluetoothDeviceInfo))); // 디스커버리 시작 discoveryAgent->start(); //...}// 로컬 슬롯에서 발견된 디바이스에 대한 정보를 읽습니다void MyClass::deviceDiscovered(const QBluetoothDeviceInfo &device){
    qDebug() << "Found new device:" << device.name() << '(' << device.address().toString() << ')';

비동기적으로 결과를 검색하려면 deviceDiscovered() 신호에 연결하세요. 검색된 모든 디바이스의 목록을 가져오려면 finished() 신호 뒤에 discoveredDevices()를 호출하세요.

이 클래스는 클래식 및 저에너지 블루투스 장치를 검색하는 데 사용할 수 있습니다. 개별 디바이스 유형은 QBluetoothDeviceInfo::coreConfigurations() 속성을 통해 확인할 수 있습니다. 대부분의 경우 discoveredDevices()에서 반환되는 목록에는 두 가지 유형의 장치가 모두 포함됩니다. 그러나 모든 플랫폼에서 두 가지 유형의 디바이스를 모두 감지할 수 있는 것은 아닙니다. 이러한 제한이 있는 플랫폼(예: iOS는 저에너지 검색만 지원)에서는 검색 프로세스가 지원되는 유형으로 검색을 제한합니다.

참고: Android 6.0부터 디바이스 검색 기능을 사용하려면 ACCESS_COARSE_LOCATION이 필요합니다.

참고: Win32 백엔드는 현재 RSSI(수신 신호 강도 표시기)와 제조업체별 데이터 또는 검색 후 Bluetooth LE 장치에서 알리는 기타 데이터 업데이트를 지원하지 않습니다.

멤버 유형 문서

열거형 QBluetoothDeviceDiscoveryAgent::DiscoveryMethod
플래그 QBluetoothDeviceDiscoveryAgent::DiscoveryMethods

이 열거형은 QBluetoothDeviceDiscoveryAgent 에 사용되는 검색 방법의 유형을 설명합니다.

Constant설명
QBluetoothDeviceDiscoveryAgent::NoMethod0x0검색이 불가능합니다. 사용 가능한 방법이 지원되지 않습니다.
QBluetoothDeviceDiscoveryAgent::ClassicMethod0x01검색 프로세스가 Bluetooth 클래식(BaseRate) 장치를 검색합니다.
QBluetoothDeviceDiscoveryAgent::LowEnergyMethod0x02검색 프로세스가 Bluetooth 저에너지 장치를 검색합니다.

DiscoveryMethods 유형은 QFlags<DiscoveryMethod>에 대한 typedef입니다. 이 유형은 DiscoveryMethod 값의 OR 조합을 저장합니다.

supportedDiscoveryMethods()도 참조하세요 .

enum QBluetoothDeviceDiscoveryAgent::Error

Bluetooth 장치를 검색하는 동안 발견되는 모든 가능한 오류 조건을 나타냅니다.

상수설명
QBluetoothDeviceDiscoveryAgent::NoError0오류가 발생하지 않았습니다.
QBluetoothDeviceDiscoveryAgent::PoweredOffError2Bluetooth 어댑터의 전원이 꺼져 있으므로 검색을 수행하기 전에 전원을 켜세요.
QBluetoothDeviceDiscoveryAgent::InputOutputError1장치에서 쓰거나 읽는 동안 오류가 발생했습니다.
QBluetoothDeviceDiscoveryAgent::InvalidBluetoothAdapterError3전달된 로컬 어댑터 주소가 로컬 Bluetooth 장치의 실제 어댑터 주소와 일치하지 않습니다.
QBluetoothDeviceDiscoveryAgent::UnsupportedPlatformError (since Qt 5.5)4현재 플랫폼에서 장치 검색이 불가능하거나 구현되지 않았습니다. 이 오류는 start()에 대한 호출에 대한 응답으로 설정됩니다. 이러한 경우의 예로는 Bluetooth 장치 검색을 전혀 지원하지 않는 5.0 이하의 iOS 버전이 있습니다.
QBluetoothDeviceDiscoveryAgent::UnsupportedDiscoveryMethod (since Qt 5.8)5요청된 검색 방법 중 하나가 현재 플랫폼에서 지원되지 않습니다.
QBluetoothDeviceDiscoveryAgent::LocationServiceTurnedOffError (since Qt 6.2)6위치 서비스가 꺼져 있습니다. 위치 서비스가 꺼져 있으면 Bluetooth API를 사용할 수 없습니다.
QBluetoothDeviceDiscoveryAgent::MissingPermissionsError (since Qt 6.4)7운영 체제에서 사용자가 부여하지 않은 권한을 요청합니다.
QBluetoothDeviceDiscoveryAgent::UnknownError100알 수 없는 오류가 발생했습니다.

멤버 기능 문서

[explicit] QBluetoothDeviceDiscoveryAgent::QBluetoothDeviceDiscoveryAgent(QObject *parent = nullptr)

부모 parent 를 사용하여 새 Bluetooth 장치 검색 에이전트를 구성합니다.

[explicit] QBluetoothDeviceDiscoveryAgent::QBluetoothDeviceDiscoveryAgent(const QBluetoothAddress &deviceAdapter, QObject *parent = nullptr)

parent 를 사용하여 새 Bluetooth 장치 검색 에이전트를 구축합니다.

장치 검색에는 deviceAdapter 을 사용합니다. deviceAdapter 을 기본으로 구성하면 결과 QBluetoothDeviceDiscoveryAgent 객체는 로컬 기본 블루투스 어댑터를 사용합니다.

로컬 어댑터가 아닌 deviceAdapter 가 지정되면 error()는 InvalidBluetoothAdapterError 로 설정됩니다. 따라서 이 생성자를 사용한 직후에 오류 플래그를 테스트하는 것이 좋습니다.

error()도 참조하세요 .

[virtual noexcept] QBluetoothDeviceDiscoveryAgent::~QBluetoothDeviceDiscoveryAgent()

에 대한 소멸자 ~QBluetoothDeviceDiscoveryAgent()

[signal] void QBluetoothDeviceDiscoveryAgent::canceled()

이 신호는 stop() 호출에 의해 장치 검색이 중단될 때 전송됩니다.

[signal] void QBluetoothDeviceDiscoveryAgent::deviceDiscovered(const QBluetoothDeviceInfo &info)

이 신호는 info 에서 설명하는 블루투스 장치가 발견될 때 방출됩니다.

이 신호는 가장 중요한 장치 정보가 수집되는 즉시 방출됩니다. 그러나 finished() 신호가 전송되지 않는 한 이미 검색된 장치에 대해서도 정보 수집이 계속됩니다. 이는 특히 신호 강도 정보(RSSI) 및 제조사 데이터 업데이트에 해당됩니다. 사용 사례에 지속적인 제조사 데이터 또는 RSSI 업데이트가 필요한 경우 검색이 완료된 후 discoveredDevices()를 통해 디바이스 정보를 검색하거나 deviceUpdated() 신호를 수신하는 것이 좋습니다.

lowEnergyDiscoveryTimeout()가 0보다 큰 경우 info 의 속성이 하나 이상 변경될 때만 신호가 전송됩니다. 이는 보다 정확한 정보가 제공될 때 업데이트를 받으려는 욕구를 반영합니다. 이 동작의 예외는 lowEnergyDiscoveryTimeout0 으로 설정된 경우입니다. 0 의 타임아웃은 시간이 지남에 따라 저에너지 디바이스의 출현 및 사라짐을 모니터링하려는 욕구를 나타냅니다. 이 조건에서는 마지막 신호 방출 이후 info 이 변경되지 않더라도 deviceDiscovered() 신호가 방출됩니다.

QBluetoothDeviceInfo::rssi() 및 lowEnergyDiscoveryTimeout()도 참조하세요 .

[signal] void QBluetoothDeviceDiscoveryAgent::deviceUpdated(const QBluetoothDeviceInfo &info, QBluetoothDeviceInfo::Fields updatedFields)

이 신호는 상담원이 info 에 설명된 블루투스 장치에 대한 추가 정보를 수신할 때 방출됩니다. updatedFields 플래그는 어떤 정보가 업데이트되었는지 알려줍니다.

검색 중에 signal strengthmanufacturerData 과 같은 일부 정보는 동적으로 변경될 수 있습니다. 이 신호는 애플리케이션이 이 데이터를 표시하는 경우 검색이 완료될 때까지 기다리지 않고 업데이트할 수 있음을 알려줍니다.

QBluetoothDeviceInfo::rssi() 및 lowEnergyDiscoveryTimeout()도 참조하세요 .

QList<QBluetoothDeviceInfo> QBluetoothDeviceDiscoveryAgent::discoveredDevices() const

검색된 모든 블루투스 디바이스 목록을 반환합니다.

QBluetoothDeviceDiscoveryAgent::Error QBluetoothDeviceDiscoveryAgent::error() const

마지막 오류를 반환합니다.

검색을 다시 시작하면 가능한 모든 이전 오류가 지워집니다.

[signal, since 6.2] void QBluetoothDeviceDiscoveryAgent::errorOccurred(QBluetoothDeviceDiscoveryAgent::Error error)

이 신호는 Bluetooth 장치를 검색하는 동안 error 이 발생하면 전송됩니다. error 매개변수는 발생한 오류를 설명합니다.

이 함수는 Qt 6.2에 도입되었습니다.

error() 및 errorString()도 참조하세요 .

QString QBluetoothDeviceDiscoveryAgent::errorString() const

마지막 오류에 대한 사람이 읽을 수 있는 설명을 반환합니다.

error() 및 errorOccurred()도 참조하세요 .

[signal] void QBluetoothDeviceDiscoveryAgent::finished()

이 신호는 Bluetooth 장치 검색이 완료되면 방출됩니다. 장치 검색이 오류로 완료되면 이 신호가 전송되지 않습니다.

bool QBluetoothDeviceDiscoveryAgent::isActive() const

에이전트가 현재 블루투스 장치를 검색 중이면 true를 반환하고, 그렇지 않으면 false를 반환합니다.

int QBluetoothDeviceDiscoveryAgent::lowEnergyDiscoveryTimeout() const

블루투스 저에너지 디바이스 검색에 적용되는 시간 제한(밀리초)을 반환합니다. -1 값은 플랫폼이 이 속성을 지원하지 않으며 장치 검색의 시간 제한을 조정할 수 없음을 의미합니다. 반환 값 0stop()을 통해 수동으로 중지해야 하는 무한 검색을 의미합니다.

setLowEnergyDiscoveryTimeout()도 참조하세요 .

void QBluetoothDeviceDiscoveryAgent::setLowEnergyDiscoveryTimeout(int timeout)

Bluetooth 저에너지 장치 검색의 최대 검색 시간을 timeout (밀리초)로 설정합니다. timeout0 인 경우 검색은 stop()가 호출될 때까지 실행됩니다.

이는 Bluetooth 저에너지 디바이스의 검색 프로세스가 대부분 개방형이라는 사실을 반영합니다. 플랫폼은 검색이 수동으로 중지될 때까지 계속해서 더 많은 디바이스를 찾습니다. 시간 초과로 인해 검색은 timeout 밀리초 후에 중단됩니다. 물론 stop()를 호출하여 검색을 수동으로 중단할 수도 있습니다.

새 시간 제한 값은 디바이스 검색이 다시 시작될 때까지 적용되지 않습니다. 또한 시간 제한은 기존 Bluetooth 장치 검색에는 영향을 미치지 않습니다. 플랫폼에 따라 클래식 검색은 전체 검색 프로세스에 timeout 을 넘어 더 많은 시간이 추가될 수 있습니다.

안정적인 Bluetooth 저에너지 검색을 위해서는 최소 40000밀리초를 사용하세요.

lowEnergyDiscoveryTimeout()도 참조하세요 .

[slot] void QBluetoothDeviceDiscoveryAgent::start()

아직 시작되지 않은 경우 Bluetooth 장치 검색을 시작합니다.

각 장치가 검색될 때마다 deviceDiscovered() 신호가 전송됩니다. 장치 검색이 완료되면 finished() 신호가 전송됩니다. 이 검색은 플랫폼에서 지원되는 최대 검색 방법 집합을 활용합니다.

supportedDiscoveryMethods()도 참조하세요 .

[slot] void QBluetoothDeviceDiscoveryAgent::start(QBluetoothDeviceDiscoveryAgent::DiscoveryMethods methods)

블루투스 장치 검색이 아직 시작되지 않았고 제공된 methods 이 지원되는 경우 블루투스 장치 검색을 시작합니다. methods 검색은 장치 검색의 범위를 제한합니다. 예를 들어 대상 서비스 또는 디바이스가 Bluetooth 저에너지 디바이스인 경우 이 기능을 사용하면 검색을 Bluetooth 저에너지 디바이스로 제한하여 검색 시간을 크게 줄일 수 있습니다.

참고: methods 은 검색 유형만 결정하며 결과의 필터링을 의미하지는 않습니다. 예를 들어 methodsLowEnergyMethod 으로만 설정되어 있어도 검색에 기존 블루투스 디바이스가 포함될 수 있습니다. 이는 이전에 캐시된 검색 결과가 검색 결과에 포함되었을 수 있기 때문에 발생할 수 있습니다.

[slot] void QBluetoothDeviceDiscoveryAgent::stop()

블루투스 장치 검색을 중지합니다. 장치 검색이 취소되면 취소() 신호가 전송됩니다. start()는 취소 신호가 수신되기 전에 호출될 수 있습니다. start ()가 호출되면 이전 검색의 취소 신호가 삭제됩니다.

[static] QBluetoothDeviceDiscoveryAgent::DiscoveryMethods QBluetoothDeviceDiscoveryAgent::supportedDiscoveryMethods()

이 함수는 현재 플랫폼에서 지원하는 검색 방법을 반환합니다. 디바이스 검색 범위를 제한하는 데 사용할 수 있습니다.

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