QBluetoothDeviceDiscoveryAgent Class
The QBluetoothDeviceDiscoveryAgent class discovers the Bluetooth devices nearby. More...
| Header: | #include <QBluetoothDeviceDiscoveryAgent> |
| qmake: | QT += bluetooth |
| Since: | Qt 5.2 |
| Inherits: | QObject |
This class was introduced in Qt 5.2.
Public Types
| enum | DiscoveryMethod { NoMethod, ClassicMethod, LowEnergyMethod } |
| enum | Error { NoError, PoweredOffError, InputOutputError, InvalidBluetoothAdapterError, UnsupportedPlatformError, …, UnknownError } |
| enum | InquiryType { GeneralUnlimitedInquiry, LimitedInquiry } |
Properties
- inquiryType : QBluetoothDeviceDiscoveryAgent::InquiryType
Public Functions
| QBluetoothDeviceDiscoveryAgent::InquiryType | inquiryType() const |
| void | setInquiryType(QBluetoothDeviceDiscoveryAgent::InquiryType type) |
Detailed Description
To discover the nearby Bluetooth devices:
- create an instance of QBluetoothDeviceDiscoveryAgent,
- connect to either the deviceDiscovered() or finished() signals,
- and call start().
void MyClass::startDeviceDiscovery() { // Create a discovery agent and connect to its signals QBluetoothDeviceDiscoveryAgent *discoveryAgent = new QBluetoothDeviceDiscoveryAgent(this); connect(discoveryAgent, SIGNAL(deviceDiscovered(QBluetoothDeviceInfo)), this, SLOT(deviceDiscovered(QBluetoothDeviceInfo))); // Start a discovery discoveryAgent->start(); //... } // In your local slot, read information about the found devices void MyClass::deviceDiscovered(const QBluetoothDeviceInfo &device) { qDebug() << "Found new device:" << device.name() << '(' << device.address().toString() << ')'; }
To retrieve results asynchronously, connect to the deviceDiscovered() signal. To get a list of all discovered devices, call discoveredDevices() after the finished() signal.
This class can be used to discover Classic and Low Energy Bluetooth devices. The individual device type can be determined via the QBluetoothDeviceInfo::coreConfigurations() attribute. In most cases the list returned by discoveredDevices() contains both types of devices. However not every platform can detect both types of devices. On platforms with this limitation (for example iOS only suports Low Energy discovery), the discovery process will limit the search to the type which is supported.
Note: Since Android 6.0 the ability to detect devices requires ACCESS_COARSE_LOCATION.
Note: Due to API limitations it is only possible to find devices that have been paired using Windows' settings on Windows.
Note: The Win32 backend currently does not support the Received Signal Strength Indicator (RSSI), as well as the Manufacturer Specific Data, or other data updates advertised by Bluetooth LE devices after discovery.
Member Type Documentation
enum QBluetoothDeviceDiscoveryAgent::DiscoveryMethod
This enum descibes the type of discovery method employed by the QBluetoothDeviceDiscoveryAgent.
| Constant | Value | Description |
|---|---|---|
QBluetoothDeviceDiscoveryAgent::NoMethod | 0x0 | The discovery is not possible. None of the available methods are supported. |
QBluetoothDeviceDiscoveryAgent::ClassicMethod | 0x01 | The discovery process searches for Bluetooth Classic (BaseRate) devices. |
QBluetoothDeviceDiscoveryAgent::LowEnergyMethod | 0x02 | The discovery process searches for Bluetooth Low Energy devices. |
This enum was introduced or modified in Qt 5.8.
See also supportedDiscoveryMethods().
enum QBluetoothDeviceDiscoveryAgent::Error
Indicates all possible error conditions found during Bluetooth device discovery.
| Constant | Value | Description |
|---|---|---|
QBluetoothDeviceDiscoveryAgent::NoError | 0 | No error has occurred. |
QBluetoothDeviceDiscoveryAgent::PoweredOffError | 2 | The Bluetooth adaptor is powered off, power it on before doing discovery. |
QBluetoothDeviceDiscoveryAgent::InputOutputError | 1 | Writing or reading from the device resulted in an error. |
QBluetoothDeviceDiscoveryAgent::InvalidBluetoothAdapterError | 3 | The passed local adapter address does not match the physical adapter address of any local Bluetooth device. |
QBluetoothDeviceDiscoveryAgent::UnsupportedPlatformError | 4 | Device discovery is not possible or implemented on the current platform. The error is set in response to a call to start(). An example for such cases are iOS versions below 5.0 which do not support Bluetooth device search at all. This value was introduced by Qt 5.5. |
QBluetoothDeviceDiscoveryAgent::UnsupportedDiscoveryMethod | 5 | One of the requested discovery methods is not supported by the current platform. This value was introduced by Qt 5.8. |
QBluetoothDeviceDiscoveryAgent::UnknownError | 100 | An unknown error has occurred. |
enum QBluetoothDeviceDiscoveryAgent::InquiryType
This enum describes the inquiry type used while discovering Bluetooth devices.
| Constant | Value | Description |
|---|---|---|
QBluetoothDeviceDiscoveryAgent::GeneralUnlimitedInquiry | 0 | A general unlimited inquiry. Discovers all visible Bluetooth devices in the local vicinity. |
QBluetoothDeviceDiscoveryAgent::LimitedInquiry | 1 | A limited inquiry discovers devices that are in limited inquiry mode. |
LimitedInquiry is not supported on all platforms. If it is requested on a platform that does not support it, GeneralUnlimitedInquiry will be used instead. Setting LimitedInquiry is useful for multi-player Bluetooth-based games that needs faster communication between the devices. The phone scans for devices in LimitedInquiry and Service Discovery is done on one or two devices to speed up the service scan. After the game has connected to the device it intended to, the device returns to GeneralUnlimitedInquiry.
Property Documentation
inquiryType : QBluetoothDeviceDiscoveryAgent::InquiryType
type of inquiry scan to be used while discovering devices
This property affects the type of inquiry scan which is performed while discovering devices.
By default, this property is set to GeneralUnlimitedInquiry.
Not all platforms support LimitedInquiry.
Access functions:
| QBluetoothDeviceDiscoveryAgent::InquiryType | inquiryType() const |
| void | setInquiryType(QBluetoothDeviceDiscoveryAgent::InquiryType type) |
See also InquiryType.