summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIvan Solovev <ivan.solovev@qt.io>2021-11-24 17:05:31 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-11-26 10:23:23 +0000
commita3e71fa606d0d9e2741fda322a05a61868802be3 (patch)
treed059c2753246a7d1fa6b7032ae882e4e841a1776
parent22658a768a6db420830eb4020232c853f88bbb02 (diff)
Windows: fix object destruction order when terminating helper threadsv6.2.2
Windows implementation of QLowEnergyController is using helper threads to perform device connection and characteristics read for services. In both cases a new QObject-derived class instance is created and moved to a helper QThread. A QThread::finished signal was used to destroy both the helper thread and the object. This was creating a situation when the order of destruction for a thread and a nested object was not specified. In practice that could lead to hangs when reading multiple service characteristics, which is specially seen on Windows 11. This patch uses QThread::finished signal to destroy only the nested object. Later on, the object's QObject::destroyed signal is used to destroy the thread itself. Task-number: QTBUG-97578 Change-Id: Ic973b835496b6098d47cd1e124315903c143e3e1 Reviewed-by: Oliver Wolff <oliver.wolff@qt.io> (cherry picked from commit 981e3f10f48580641f5e2365953ec8a17b5c96a2) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/bluetooth/qlowenergycontroller_winrt.cpp4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/bluetooth/qlowenergycontroller_winrt.cpp b/src/bluetooth/qlowenergycontroller_winrt.cpp
index 32e4489a..c9119ac7 100644
--- a/src/bluetooth/qlowenergycontroller_winrt.cpp
+++ b/src/bluetooth/qlowenergycontroller_winrt.cpp
@@ -699,8 +699,8 @@ void QLowEnergyControllerPrivateWinRT::connectToDevice()
connect(this, &QLowEnergyControllerPrivateWinRT::abortConnection, worker,
&QWinRTLowEnergyConnectionHandler::handleDeviceDisconnectRequest);
connect(thread, &QThread::started, worker, &QWinRTLowEnergyConnectionHandler::connectToDevice);
- connect(thread, &QThread::finished, thread, &QObject::deleteLater);
connect(thread, &QThread::finished, worker, &QObject::deleteLater);
+ connect(worker, &QObject::destroyed, thread, &QObject::deleteLater);
connect(worker, &QWinRTLowEnergyConnectionHandler::errorOccurred, this,
[this](const QString &msg) { handleConnectionError(msg.toUtf8().constData()); });
connect(worker, &QWinRTLowEnergyConnectionHandler::deviceConnected, this,
@@ -1188,8 +1188,8 @@ void QLowEnergyControllerPrivateWinRT::discoverServiceDetails(
QThread *thread = new QThread;
worker->moveToThread(thread);
connect(thread, &QThread::started, worker, &QWinRTLowEnergyServiceHandler::obtainCharList);
- connect(thread, &QThread::finished, thread, &QObject::deleteLater);
connect(thread, &QThread::finished, worker, &QObject::deleteLater);
+ connect(worker, &QObject::destroyed, thread, &QObject::deleteLater);
connect(worker, &QWinRTLowEnergyServiceHandler::errorOccured,
this, &QLowEnergyControllerPrivateWinRT::handleServiceHandlerError);
connect(worker, &QWinRTLowEnergyServiceHandler::charListObtained,