summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJuha Vuolle <juha.vuolle@insta.fi>2021-09-14 13:35:25 +0300
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-09-20 13:46:36 +0000
commit2fa086c8850f3b460f447cc5e2f7ef653767c33e (patch)
tree67f4538c5fe17626090e30ecd4f814a7e3553122 /src
parentd5edf7bcb67bfb24bb08b471b74721efd2fc11ca (diff)
Move connecting to a LE device to background on Windows
The BT LE connectToDevice() method on Windows was a synchronous operation for the caller by blocking while spinning the event loop to keep rest of the application responsive. Other platforms behave differently. This commit makes the connect call to return immediately while scheduling the connection in the background. The QTBUG-83633 was originally about slightly different crash which seems not be reproducible anymore, but this crash was found while investigating that and is investigated in that item. Task-number: QTBUG-83633 Change-Id: I092a94f2437351d27da758db6746f5b24d5fa9c7 Reviewed-by: Alex Blasche <alexander.blasche@qt.io> (cherry picked from commit 3fc3716e0cd209cd9475d632925a9148b40b2f1d) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src')
-rw-r--r--src/bluetooth/qlowenergycontroller_winrt.cpp12
-rw-r--r--src/bluetooth/qlowenergycontroller_winrt_p.h1
2 files changed, 11 insertions, 2 deletions
diff --git a/src/bluetooth/qlowenergycontroller_winrt.cpp b/src/bluetooth/qlowenergycontroller_winrt.cpp
index 8ad71785..73bebd94 100644
--- a/src/bluetooth/qlowenergycontroller_winrt.cpp
+++ b/src/bluetooth/qlowenergycontroller_winrt.cpp
@@ -459,14 +459,22 @@ void QLowEnergyControllerPrivateWinRT::connectToDevice()
{
qCDebug(QT_BT_WINDOWS) << __FUNCTION__;
mAbortPending = false;
- Q_Q(QLowEnergyController);
if (remoteDevice.isNull()) {
qCWarning(QT_BT_WINDOWS) << "Invalid/null remote device address";
setError(QLowEnergyController::UnknownRemoteDeviceError);
return;
}
-
setState(QLowEnergyController::ConnectingState);
+ // Queue the device connecting to happen in the background
+ QMetaObject::invokeMethod(this,
+ &QLowEnergyControllerPrivateWinRT::doConnectToDevice,
+ Qt::QueuedConnection);
+}
+
+void QLowEnergyControllerPrivateWinRT::doConnectToDevice()
+{
+ qCDebug(QT_BT_WINDOWS) << __FUNCTION__;
+ Q_Q(QLowEnergyController);
ComPtr<IBluetoothLEDeviceStatics> deviceStatics;
HRESULT hr = GetActivationFactory(
diff --git a/src/bluetooth/qlowenergycontroller_winrt_p.h b/src/bluetooth/qlowenergycontroller_winrt_p.h
index 04d56f26..d6b9d1b1 100644
--- a/src/bluetooth/qlowenergycontroller_winrt_p.h
+++ b/src/bluetooth/qlowenergycontroller_winrt_p.h
@@ -136,6 +136,7 @@ signals:
private slots:
void handleCharacteristicChanged(quint16 charHandle, const QByteArray &data);
void handleServiceHandlerError(const QString &error);
+ void doConnectToDevice();
private:
void connectToPairedDevice();