diff options
Diffstat (limited to 'examples/bluetooth/lowenergyscanner/Devices.qml')
-rw-r--r-- | examples/bluetooth/lowenergyscanner/Devices.qml | 43 |
1 files changed, 33 insertions, 10 deletions
diff --git a/examples/bluetooth/lowenergyscanner/Devices.qml b/examples/bluetooth/lowenergyscanner/Devices.qml index 40afce7f..b41c259d 100644 --- a/examples/bluetooth/lowenergyscanner/Devices.qml +++ b/examples/bluetooth/lowenergyscanner/Devices.qml @@ -3,6 +3,7 @@ // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause pragma ComponentBehavior: Bound +import QtCore import QtQuick Rectangle { @@ -14,6 +15,19 @@ Rectangle { width: 300 height: 600 + function toggleDiscovery() { + if (!Device.state) { + Device.startDeviceDiscovery() + // if startDeviceDiscovery() failed Device.state is not set + if (Device.state) { + info.dialogText = "Searching..." + info.visible = true + } + } else { + Device.stopDeviceDiscovery() + } + } + onDeviceStateChanged: { if (!Device.state) info.visible = false @@ -99,23 +113,32 @@ Rectangle { onButtonClick: Device.useRandomAddress = !Device.useRandomAddress } + //! [permission-object] + BluetoothPermission { + id: permission + communicationModes: BluetoothPermission.Access + onStatusChanged: { + if (permission.status === Qt.PermissionStatus.Denied) + Device.update = "Bluetooth permission required" + else if (permission.status === Qt.PermissionStatus.Granted) + devicesPage.toggleDiscovery() + } + } + //! [permission-object] + Menu { id: menu anchors.bottom: parent.bottom menuWidth: parent.width menuHeight: (parent.height / 6) menuText: Device.update + //! [permission-request] onButtonClick: { - if (!Device.state) { - Device.startDeviceDiscovery() - // if startDeviceDiscovery() failed Device.state is not set - if (Device.state) { - info.dialogText = "Searching..." - info.visible = true - } - } else { - Device.stopDeviceDiscovery() - } + if (permission.status === Qt.PermissionStatus.Undetermined) + permission.request() + else if (permission.status === Qt.PermissionStatus.Granted) + devicesPage.toggleDiscovery() } + //! [permission-request] } } |