summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/bluetooth/lowenergyscanner/device.cpp20
-rw-r--r--examples/bluetooth/lowenergyscanner/doc/src/lowenergyscanner.qdoc6
2 files changed, 26 insertions, 0 deletions
diff --git a/examples/bluetooth/lowenergyscanner/device.cpp b/examples/bluetooth/lowenergyscanner/device.cpp
index d645931c..f6c346c3 100644
--- a/examples/bluetooth/lowenergyscanner/device.cpp
+++ b/examples/bluetooth/lowenergyscanner/device.cpp
@@ -9,6 +9,12 @@
#include <qbluetoothlocaldevice.h>
#include <qbluetoothdeviceinfo.h>
#include <qbluetoothservicediscoveryagent.h>
+
+#if QT_CONFIG(permissions)
+#include <QGuiApplication>
+#include <QPermission>
+#endif
+
#include <QDebug>
#include <QList>
#include <QMetaEnum>
@@ -43,6 +49,20 @@ Device::~Device()
void Device::startDeviceDiscovery()
{
+#if QT_CONFIG(permissions)
+ //! [les-bluetooth-permission]
+ const auto permissionStatus = qApp->checkPermission(QBluetoothPermission{});
+ if (permissionStatus == Qt::PermissionStatus::Undetermined) {
+ qApp->requestPermission(QBluetoothPermission{}, this, &Device::startDeviceDiscovery);
+ return;
+ }
+ if (permissionStatus == Qt::PermissionStatus::Denied) {
+ setUpdate("Bluetooth permission required.");
+ return;
+ }
+ //! [les-bluetooth-permission]
+#endif // QT_CONFIG(permissions)
+
qDeleteAll(devices);
devices.clear();
emit devicesUpdated();
diff --git a/examples/bluetooth/lowenergyscanner/doc/src/lowenergyscanner.qdoc b/examples/bluetooth/lowenergyscanner/doc/src/lowenergyscanner.qdoc
index bba28796..9d013203 100644
--- a/examples/bluetooth/lowenergyscanner/doc/src/lowenergyscanner.qdoc
+++ b/examples/bluetooth/lowenergyscanner/doc/src/lowenergyscanner.qdoc
@@ -32,6 +32,12 @@
\include examples-run.qdocinc
+ \section1 Requesting Permission to use Bluetooth
+ Before the application can start using Bluetooth, we have to check Bluetooth
+ permission, and if its status is not determined yet, request this permission:
+
+ \snippet lowenergyscanner/device.cpp les-bluetooth-permission
+
\section1 Scanning for Devices
The first step is to find all peripheral devices. The devices can be found using