The first thing you need to do is search for devices, which is called discovery. It entails putting the Bluetooth device into search, or discovery mode. You then receive a list of devices address with which you can connect or pair to be able to access and share data.
Let's look at how that is done in Qt using QBluetoothDeviceDiscoveryAgent
.
The QBluetoothDeviceDiscoveryAgent
class is responsible for the device discovery search. It will emit the deviceDiscovered
signal when any Bluetooth is found:
QBluetoothDeviceDiscoveryAgent*discoveryAgent=newQBluetoothDeviceDiscoveryAgent(this);connect(discoveryAgent,SIGNAL(deviceDiscovered(QBluetoothDeviceInfo)),
this,SLOT(newDevice(QBluetoothDeviceInfo)));
discoveryAgent->start(QBluetoothDeviceDiscoveryAgent::LowEnergyMethod));
Note
The source code can be found on the Git repository under the Chapter06-1a
directory, in the cp6
branch.
The call to start()
will initiate...