summaryrefslogtreecommitdiffstats
path: root/src/bluetooth/qlowenergycontroller.cpp
diff options
context:
space:
mode:
authorAndreas Buhr <andreas@andreasbuhr.de>2021-03-11 13:53:11 +0100
committerAndreas Buhr <andreas.buhr@qt.io>2021-03-25 20:44:39 +0100
commitbe0809acdfd3db4c95f88965ad70d9c79d3c2f40 (patch)
treec336d2ace794c5b4a118c5f5a2fe9b9d80865e1d /src/bluetooth/qlowenergycontroller.cpp
parente41fdb17dbf8fd92689cc79cac08b6072e9d656f (diff)
Add option to specify host device when starting BTLE peripheral
There was no option to specify which host device to use when starting BTLE peripheral QLowEnergyController. This path adds this option. Fixes: QTBUG-91904 Change-Id: I884bc354ae1d7541ed752670556e98d6698130d7 Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
Diffstat (limited to 'src/bluetooth/qlowenergycontroller.cpp')
-rw-r--r--src/bluetooth/qlowenergycontroller.cpp37
1 files changed, 33 insertions, 4 deletions
diff --git a/src/bluetooth/qlowenergycontroller.cpp b/src/bluetooth/qlowenergycontroller.cpp
index 5310590a..324c661a 100644
--- a/src/bluetooth/qlowenergycontroller.cpp
+++ b/src/bluetooth/qlowenergycontroller.cpp
@@ -423,7 +423,8 @@ QLowEnergyController *QLowEnergyController::createCentral(const QBluetoothDevice
/*!
Returns a new object of this class that is in the \l PeripheralRole and has the
parent object \a parent.
- Typically, the next step is to call \l startAdvertising() on the returned object.
+ Typically, the next steps are to add some services and finally
+ call \l startAdvertising() on the returned object.
The controller uses the local default Bluetooth adapter for the connection management.
@@ -432,10 +433,33 @@ QLowEnergyController *QLowEnergyController::createCentral(const QBluetoothDevice
*/
QLowEnergyController *QLowEnergyController::createPeripheral(QObject *parent)
{
- return new QLowEnergyController(parent);
+ return new QLowEnergyController(QBluetoothAddress(), parent);
}
-QLowEnergyController::QLowEnergyController(QObject *parent)
+/*!
+ Returns a new object of this class that is in the \l PeripheralRole and has the
+ parent object \a parent and is using \a localDevice.
+ Typically, the next steps are to add some services and finally
+ call \l startAdvertising() on the returned object.
+
+ The peripheral is created on \a localDevice. If \a localDevice is invalid,
+ the local default device is automatically selected. If \a localDevice specifies
+ a local device that is not a local Bluetooth adapter, \l error() is set to
+ \l InvalidBluetoothAdapterError.
+
+ Selecting \a localDevice is only supported on Linux. On other platform,
+ the parameter is ignored.
+
+ \sa QLowEnergyController::PeripheralRole
+ \since 6.2
+ */
+QLowEnergyController *QLowEnergyController::createPeripheral(const QBluetoothAddress &localDevice,
+ QObject *parent)
+{
+ return new QLowEnergyController(localDevice, parent);
+}
+
+QLowEnergyController::QLowEnergyController(const QBluetoothAddress &localDevice, QObject *parent)
: QObject(parent)
{
d_ptr = privateController(PeripheralRole);
@@ -443,7 +467,12 @@ QLowEnergyController::QLowEnergyController(QObject *parent)
Q_D(QLowEnergyController);
d->q_ptr = this;
d->role = PeripheralRole;
- d->localAdapter = QBluetoothLocalDevice().address();
+
+ if (localDevice.isNull())
+ d->localAdapter = QBluetoothLocalDevice().address();
+ else
+ d->localAdapter = localDevice;
+
d->init();
}