From bf7590c3433639350ba23f4bd73e931bf1f3bdb9 Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Fri, 3 Aug 2018 19:28:06 +0200 Subject: [PATCH] fix crash in BT setup --- .../wifisetup/bluetoothdiscovery.cpp | 12 +++++------ .../ui/connection/BluetoothDiscoveryPage.qml | 20 +++++++++---------- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/libnymea-app-core/wifisetup/bluetoothdiscovery.cpp b/libnymea-app-core/wifisetup/bluetoothdiscovery.cpp index 02037848..2027b46d 100644 --- a/libnymea-app-core/wifisetup/bluetoothdiscovery.cpp +++ b/libnymea-app-core/wifisetup/bluetoothdiscovery.cpp @@ -157,22 +157,22 @@ void BluetoothDiscovery::deviceDiscovered(const QBluetoothDeviceInfo &deviceInfo // Check if we already have added this device info foreach (BluetoothDeviceInfo *di, m_deviceInfos->deviceInfos()) { - if (di->name() == deviceInformation->name() && di->address() == deviceInformation->address()) { + if (di->address() == deviceInformation->address()) { qWarning() << "BluetoothDiscover: device" << deviceInformation->name() << "(" << deviceInformation->address() << ") already added"; deviceInformation->deleteLater(); - deviceInformation = nullptr; + return; } } - if (deviceInformation) - m_deviceInfos->addBluetoothDeviceInfo(deviceInformation); - + m_deviceInfos->addBluetoothDeviceInfo(deviceInformation); } void BluetoothDiscovery::discoveryFinished() { qDebug() << "BluetoothDiscovery: Discovery finished"; - setDiscovering(false); + if (m_enabled) { + m_discoveryAgent->start(); + } } void BluetoothDiscovery::onError(const QBluetoothDeviceDiscoveryAgent::Error &error) diff --git a/nymea-app/ui/connection/BluetoothDiscoveryPage.qml b/nymea-app/ui/connection/BluetoothDiscoveryPage.qml index 95c55207..fa933e12 100644 --- a/nymea-app/ui/connection/BluetoothDiscoveryPage.qml +++ b/nymea-app/ui/connection/BluetoothDiscoveryPage.qml @@ -10,19 +10,8 @@ Page { header: GuhHeader { text: qsTr("Bluetooth discovery") onBackPressed: pageStack.pop() - - HeaderButton { - imageSource: Qt.resolvedUrl("../images/refresh.svg") - onClicked: { - if (Engine.bluetoothDiscovery.bluetoothAvailable) { - Engine.bluetoothDiscovery.start() - } - } - enabled: Engine.bluetoothDiscovery.bluetoothAvailable && Engine.bluetoothDiscovery.bluetoothEnabled && !Engine.bluetoothDiscovery.discovering - } } - Component.onCompleted: Engine.bluetoothDiscovery.start() function setupDevice(name, btAddress) { @@ -30,6 +19,15 @@ Page { pageStack.push(connectingPageComponent, { name: name, address: btAddress } ) } + Connections { + target: pageStack + onCurrentItemChanged: { + if (pageStack.currentItem === root) { + Engine.bluetoothDiscovery.start(); + } + } + } + ColumnLayout { anchors.fill: parent spacing: app.margins