summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAlex Blasche <alexander.blasche@qt.io>2018-10-30 16:56:38 +0100
committerJani Heikkinen <jani.heikkinen@qt.io>2018-10-31 08:19:38 +0000
commitc2b510909dc8839ff6578086051a22e8b21462e3 (patch)
tree6e9d89fc5139826a28f1f10b03919ffd758a949b /src
parent8d279a05f2570ae1b964c90efd9a5bf2ce154b76 (diff)
Ensure QObject context is retained to avoid crashesv5.12.0-beta4
If the public class is deleted pending lambda invocation can cause crashes unless QObject context is provided. This fixes a regression introduced by 819bb06c2cb3372cb1bb9ddd7f3a504f78d3452d. This was discovered while investigating QTBUG-71479. Change-Id: I3a49916ce6d9425c684863bb0b04a10bd3e652b9 Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp11
-rw-r--r--src/bluetooth/qbluetoothserver_bluez.cpp2
-rw-r--r--src/bluetooth/qbluetoothservicediscoveryagent.cpp6
-rw-r--r--src/bluetooth/qbluetoothservicediscoveryagent_android.cpp10
-rw-r--r--src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp8
5 files changed, 20 insertions, 17 deletions
diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp b/src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp
index 51546df2..bbb4ac3e 100644
--- a/src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp
+++ b/src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp
@@ -75,6 +75,7 @@ QBluetoothDeviceDiscoveryAgentPrivate::QBluetoothDeviceDiscoveryAgentPrivate(
QDBusConnection::systemBus(), parent);
QObject::connect(managerBluez5,
&OrgFreedesktopDBusObjectManagerInterface::InterfacesAdded,
+ q_ptr,
[this](const QDBusObjectPath &objectPath, InterfaceList interfacesAndProperties) {
this->_q_InterfacesAdded(objectPath, interfacesAndProperties);
});
@@ -85,7 +86,7 @@ QBluetoothDeviceDiscoveryAgentPrivate::QBluetoothDeviceDiscoveryAgentPrivate(
manager = new OrgBluezManagerInterface(QStringLiteral("org.bluez"), QStringLiteral("/"),
QDBusConnection::systemBus(), parent);
QObject::connect(&extendedDiscoveryTimer,
- &QTimer::timeout, [this]() {
+ &QTimer::timeout, q_ptr, [this]() {
this->_q_extendedDeviceDiscoveryTimeout();
});
extendedDiscoveryTimer.setInterval(10000);
@@ -162,11 +163,11 @@ void QBluetoothDeviceDiscoveryAgentPrivate::start(QBluetoothDeviceDiscoveryAgent
Q_Q(QBluetoothDeviceDiscoveryAgent);
QObject::connect(adapter, &OrgBluezAdapterInterface::DeviceFound,
- [this](const QString &address, const QVariantMap &dict) {
+ q, [this](const QString &address, const QVariantMap &dict) {
this->_q_deviceFound(address, dict);
});
QObject::connect(adapter, &OrgBluezAdapterInterface::PropertyChanged,
- [this](const QString &name, const QDBusVariant &value) {
+ q, [this](const QString &name, const QDBusVariant &value) {
this->_q_propertyChanged(name, value);
});
@@ -287,7 +288,7 @@ void QBluetoothDeviceDiscoveryAgentPrivate::startBluez5(QBluetoothDeviceDiscover
QtBluezDiscoveryManager::instance()->registerDiscoveryInterest(adapterBluez5->path());
QObject::connect(QtBluezDiscoveryManager::instance(), &QtBluezDiscoveryManager::discoveryInterrupted,
- [this](const QString &path){
+ q, [this](const QString &path){
this->_q_discoveryInterrupted(path);
});
@@ -321,7 +322,7 @@ void QBluetoothDeviceDiscoveryAgentPrivate::startBluez5(QBluetoothDeviceDiscover
discoveryTimer = new QTimer(q);
discoveryTimer->setSingleShot(true);
QObject::connect(discoveryTimer, &QTimer::timeout,
- [this]() {
+ q, [this]() {
this->_q_discoveryFinished();
});
}
diff --git a/src/bluetooth/qbluetoothserver_bluez.cpp b/src/bluetooth/qbluetoothserver_bluez.cpp
index f45aee28..54bc85a0 100644
--- a/src/bluetooth/qbluetoothserver_bluez.cpp
+++ b/src/bluetooth/qbluetoothserver_bluez.cpp
@@ -253,7 +253,7 @@ bool QBluetoothServer::listen(const QBluetoothAddress &address, quint16 port)
d->socketNotifier = new QSocketNotifier(d->socket->socketDescriptor(),
QSocketNotifier::Read);
connect(d->socketNotifier, &QSocketNotifier::activated,
- [d](){
+ this, [d](){
d->_q_newConnection();
});
}
diff --git a/src/bluetooth/qbluetoothservicediscoveryagent.cpp b/src/bluetooth/qbluetoothservicediscoveryagent.cpp
index 3260d7db..390b9f74 100644
--- a/src/bluetooth/qbluetoothservicediscoveryagent.cpp
+++ b/src/bluetooth/qbluetoothservicediscoveryagent.cpp
@@ -435,16 +435,16 @@ void QBluetoothServiceDiscoveryAgentPrivate::startDeviceDiscovery()
deviceDiscoveryAgent = new QBluetoothDeviceDiscoveryAgent(q);
#endif
QObject::connect(deviceDiscoveryAgent, &QBluetoothDeviceDiscoveryAgent::finished,
- [this](){
+ q, [this](){
this->_q_deviceDiscoveryFinished();
});
QObject::connect(deviceDiscoveryAgent, &QBluetoothDeviceDiscoveryAgent::deviceDiscovered,
- [this](const QBluetoothDeviceInfo &info){
+ q, [this](const QBluetoothDeviceInfo &info){
this->_q_deviceDiscovered(info);
});
QObject::connect(deviceDiscoveryAgent,
QOverload<QBluetoothDeviceDiscoveryAgent::Error>::of(&QBluetoothDeviceDiscoveryAgent::error),
- [this](QBluetoothDeviceDiscoveryAgent::Error newError){
+ q, [this](QBluetoothDeviceDiscoveryAgent::Error newError){
this->_q_deviceDiscoveryError(newError);
});
}
diff --git a/src/bluetooth/qbluetoothservicediscoveryagent_android.cpp b/src/bluetooth/qbluetoothservicediscoveryagent_android.cpp
index 7ab1f50c..ce2911d3 100644
--- a/src/bluetooth/qbluetoothservicediscoveryagent_android.cpp
+++ b/src/bluetooth/qbluetoothservicediscoveryagent_android.cpp
@@ -200,7 +200,7 @@ void QBluetoothServiceDiscoveryAgentPrivate::start(const QBluetoothAddress &addr
if (!receiver) {
receiver = new ServiceDiscoveryBroadcastReceiver();
QObject::connect(receiver, &ServiceDiscoveryBroadcastReceiver::uuidFetchFinished,
- [this](const QBluetoothAddress &address, const QList<QBluetoothUuid>& uuids) {
+ q, [this](const QBluetoothAddress &address, const QList<QBluetoothUuid>& uuids) {
this->_q_processFetchedUuids(address, uuids);
});
}
@@ -208,7 +208,7 @@ void QBluetoothServiceDiscoveryAgentPrivate::start(const QBluetoothAddress &addr
if (!localDeviceReceiver) {
localDeviceReceiver = new LocalDeviceBroadcastReceiver();
QObject::connect(localDeviceReceiver, &LocalDeviceBroadcastReceiver::hostModeStateChanged,
- [this](QBluetoothLocalDevice::HostMode state){
+ q, [this](QBluetoothLocalDevice::HostMode state){
this->_q_hostModeStateChanged(state);
});
}
@@ -250,7 +250,8 @@ void QBluetoothServiceDiscoveryAgentPrivate::_q_processFetchedUuids(
//could not find any service for the current address/device -> go to next one
if (address.isNull() || uuids.isEmpty()) {
if (discoveredDevices.count() == 1) {
- QTimer::singleShot(4000, qApp, [this]() {
+ Q_Q(QBluetoothServiceDiscoveryAgent);
+ QTimer::singleShot(4000, q, [this]() {
this->_q_fetchUuidsTimeout();
});
}
@@ -301,7 +302,8 @@ void QBluetoothServiceDiscoveryAgentPrivate::_q_processFetchedUuids(
//the discovery on the last device cannot immediately finish
//we have to grant the 2 seconds timeout delay
if (discoveredDevices.count() == 1) {
- QTimer::singleShot(4000, qApp, [this]() {
+ Q_Q(QBluetoothServiceDiscoveryAgent);
+ QTimer::singleShot(4000, q, [this]() {
this->_q_fetchUuidsTimeout();
});
return;
diff --git a/src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp b/src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp
index dbd084ed..e16caff6 100644
--- a/src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp
+++ b/src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp
@@ -129,7 +129,7 @@ void QBluetoothServiceDiscoveryAgentPrivate::start(const QBluetoothAddress &addr
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(deviceObjectPath, q);
watcher->setProperty("_q_BTaddress", QVariant::fromValue(address));
QObject::connect(watcher, &QDBusPendingCallWatcher::finished,
- [this](QDBusPendingCallWatcher *watcher){
+ q, [this](QDBusPendingCallWatcher *watcher){
this->_q_foundDevice(watcher);
});
}
@@ -216,7 +216,7 @@ void QBluetoothServiceDiscoveryAgentPrivate::runExternalSdpScan(
sdpScannerProcess->setProgram(fileInfo.canonicalFilePath());
q->connect(sdpScannerProcess,
QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
- [this](int exitCode, QProcess::ExitStatus status){
+ q, [this](int exitCode, QProcess::ExitStatus status){
this->_q_sdpScannerDone(exitCode, status);
});
}
@@ -396,7 +396,7 @@ void QBluetoothServiceDiscoveryAgentPrivate::_q_foundDevice(QDBusPendingCallWatc
watcher = new QDBusPendingCallWatcher(deviceObjectPath, q);
watcher->setProperty("_q_BTaddress", QVariant::fromValue(address));
QObject::connect(watcher, &QDBusPendingCallWatcher::finished,
- [this](QDBusPendingCallWatcher *watcher){
+ q, [this](QDBusPendingCallWatcher *watcher){
this->_q_createdDevice(watcher);
});
@@ -537,7 +537,7 @@ void QBluetoothServiceDiscoveryAgentPrivate::discoverServices(const QString &dev
QDBusPendingReply<ServiceMap> discoverReply = device->DiscoverServices(pattern);
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(discoverReply, q);
QObject::connect(watcher, &QDBusPendingCallWatcher::finished,
- [this](QDBusPendingCallWatcher *watcher){
+ q, [this](QDBusPendingCallWatcher *watcher){
this->_q_discoveredServices(watcher);
});
}