From 819bb06c2cb3372cb1bb9ddd7f3a504f78d3452d Mon Sep 17 00:00:00 2001 From: Alex Blasche <alexander.blasche@qt.io> Date: Wed, 22 Aug 2018 15:21:15 +0200 Subject: [PATCH] Normalize QObject::connect() statements Some cases use the Q_PRIVATE_SLOT logic which does not require QObject inheritance. Those cases were converted to lambda logic to avoid need for QObject inheritance. The Q_PRIVATE_SLOT macro was removed from qbluetoothdevicediscoveryagent.h. This is not a BC problem because the macro expands to nothing. Only moc recognizes the pattern. Change-Id: Ic7cb4cde397f9b230b6fd0b4046e59e504583e58 Reviewed-by: Oliver Wolff <oliver.wolff@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> --- .../qbluetoothdevicediscoveryagent.h | 10 ---- .../qbluetoothdevicediscoveryagent_bluez.cpp | 44 +++++++++----- src/bluetooth/qbluetoothlocaldevice_bluez.cpp | 60 +++++++++---------- src/bluetooth/qbluetoothserver.h | 4 -- src/bluetooth/qbluetoothserver_bluez.cpp | 5 +- .../qbluetoothservicediscoveryagent.cpp | 20 ++++--- .../qbluetoothservicediscoveryagent.h | 19 ------ ...bluetoothservicediscoveryagent_android.cpp | 23 ++++--- .../qbluetoothservicediscoveryagent_bluez.cpp | 30 ++++++---- 9 files changed, 111 insertions(+), 104 deletions(-) diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent.h b/src/bluetooth/qbluetoothdevicediscoveryagent.h index f24478bf..59a8b456 100644 --- a/src/bluetooth/qbluetoothdevicediscoveryagent.h +++ b/src/bluetooth/qbluetoothdevicediscoveryagent.h @@ -120,16 +120,6 @@ Q_SIGNALS: private: Q_DECLARE_PRIVATE(QBluetoothDeviceDiscoveryAgent) QBluetoothDeviceDiscoveryAgentPrivate *d_ptr; - -#if QT_CONFIG(bluez) - Q_PRIVATE_SLOT(d_func(), void _q_deviceFound(const QString &address, const QVariantMap &dict)) - Q_PRIVATE_SLOT(d_func(), void _q_propertyChanged(const QString &name, const QDBusVariant &value)) - Q_PRIVATE_SLOT(d_func(), void _q_InterfacesAdded(const QDBusObjectPath &path, InterfaceList interfaceList)) - Q_PRIVATE_SLOT(d_func(), void _q_discoveryFinished()) - Q_PRIVATE_SLOT(d_func(), void _q_discoveryInterrupted(const QString &path)) - Q_PRIVATE_SLOT(d_func(), void _q_PropertiesChanged(const QString &interface, const QVariantMap &changed_properties, const QStringList &invalidated_properties)) - Q_PRIVATE_SLOT(d_func(), void _q_extendedDeviceDiscoveryTimeout()) -#endif }; Q_DECLARE_OPERATORS_FOR_FLAGS(QBluetoothDeviceDiscoveryAgent::DiscoveryMethods) diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp b/src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp index 5791a9f9..86b7a5e7 100644 --- a/src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp +++ b/src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp @@ -67,7 +67,6 @@ QBluetoothDeviceDiscoveryAgentPrivate::QBluetoothDeviceDiscoveryAgentPrivate( lowEnergySearchTimeout(-1), // remains -1 on BlueZ 4 -> timeout not supported q_ptr(parent) { - Q_Q(QBluetoothDeviceDiscoveryAgent); if (isBluez5()) { lowEnergySearchTimeout = 20000; managerBluez5 = new OrgFreedesktopDBusObjectManagerInterface( @@ -75,8 +74,10 @@ QBluetoothDeviceDiscoveryAgentPrivate::QBluetoothDeviceDiscoveryAgentPrivate( QStringLiteral("/"), QDBusConnection::systemBus(), parent); QObject::connect(managerBluez5, - SIGNAL(InterfacesAdded(QDBusObjectPath,InterfaceList)), - q, SLOT(_q_InterfacesAdded(QDBusObjectPath,InterfaceList))); + &OrgFreedesktopDBusObjectManagerInterface::InterfacesAdded, + [this](const QDBusObjectPath &objectPath, InterfaceList interfacesAndProperties) { + this->_q_InterfacesAdded(objectPath, interfacesAndProperties); + }); // start private address monitoring BluetoothManagement::instance(); @@ -84,8 +85,9 @@ QBluetoothDeviceDiscoveryAgentPrivate::QBluetoothDeviceDiscoveryAgentPrivate( manager = new OrgBluezManagerInterface(QStringLiteral("org.bluez"), QStringLiteral("/"), QDBusConnection::systemBus(), parent); QObject::connect(&extendedDiscoveryTimer, - SIGNAL(timeout()), - q, SLOT(_q_extendedDeviceDiscoveryTimeout())); + &QTimer::timeout, [this]() { + this->_q_extendedDeviceDiscoveryTimeout(); + }); extendedDiscoveryTimer.setInterval(10000); extendedDiscoveryTimer.setSingleShot(true); } @@ -159,10 +161,14 @@ void QBluetoothDeviceDiscoveryAgentPrivate::start(QBluetoothDeviceDiscoveryAgent QDBusConnection::systemBus()); Q_Q(QBluetoothDeviceDiscoveryAgent); - QObject::connect(adapter, SIGNAL(DeviceFound(QString, QVariantMap)), - q, SLOT(_q_deviceFound(QString, QVariantMap))); - QObject::connect(adapter, SIGNAL(PropertyChanged(QString, QDBusVariant)), - q, SLOT(_q_propertyChanged(QString, QDBusVariant))); + QObject::connect(adapter, &OrgBluezAdapterInterface::DeviceFound, + [this](const QString &address, const QVariantMap &dict) { + this->_q_deviceFound(address, dict); + }); + QObject::connect(adapter, &OrgBluezAdapterInterface::PropertyChanged, + [this](const QString &name, const QDBusVariant &value) { + this->_q_propertyChanged(name, value); + }); QDBusPendingReply<QVariantMap> propertiesReply = adapter->GetProperties(); propertiesReply.waitForFinished(); @@ -280,8 +286,10 @@ void QBluetoothDeviceDiscoveryAgentPrivate::startBluez5(QBluetoothDeviceDiscover } QtBluezDiscoveryManager::instance()->registerDiscoveryInterest(adapterBluez5->path()); - QObject::connect(QtBluezDiscoveryManager::instance(), SIGNAL(discoveryInterrupted(QString)), - q, SLOT(_q_discoveryInterrupted(QString))); + QObject::connect(QtBluezDiscoveryManager::instance(), &QtBluezDiscoveryManager::discoveryInterrupted, + [this](const QString &path){ + this->_q_discoveryInterrupted(path); + }); // collect initial set of information QDBusPendingReply<ManagedObjectList> reply = managerBluez5->GetManagedObjects(); @@ -312,8 +320,10 @@ void QBluetoothDeviceDiscoveryAgentPrivate::startBluez5(QBluetoothDeviceDiscover if (!discoveryTimer) { discoveryTimer = new QTimer(q); discoveryTimer->setSingleShot(true); - QObject::connect(discoveryTimer, SIGNAL(timeout()), - q, SLOT(_q_discoveryFinished())); + QObject::connect(discoveryTimer, &QTimer::timeout, + [this]() { + this->_q_discoveryFinished(); + }); } if (lowEnergySearchTimeout > 0) { // otherwise no timeout and stop() required @@ -420,8 +430,12 @@ void QBluetoothDeviceDiscoveryAgentPrivate::deviceFoundBluez5(const QString& dev OrgFreedesktopDBusPropertiesInterface *prop = new OrgFreedesktopDBusPropertiesInterface( QStringLiteral("org.bluez"), devicePath, QDBusConnection::systemBus(), q); - QObject::connect(prop, SIGNAL(PropertiesChanged(QString,QVariantMap,QStringList)), - q, SLOT(_q_PropertiesChanged(QString,QVariantMap,QStringList))); + QObject::connect(prop, &OrgFreedesktopDBusPropertiesInterface::PropertiesChanged, + [this](const QString &interface, const QVariantMap &changedProperties, + const QStringList &invalidatedProperties) { + this->_q_PropertiesChanged(interface, changedProperties, invalidatedProperties); + }); + // remember what we have to cleanup propertyMonitors.append(prop); diff --git a/src/bluetooth/qbluetoothlocaldevice_bluez.cpp b/src/bluetooth/qbluetoothlocaldevice_bluez.cpp index f99dc46d..f02c6ab9 100644 --- a/src/bluetooth/qbluetoothlocaldevice_bluez.cpp +++ b/src/bluetooth/qbluetoothlocaldevice_bluez.cpp @@ -397,8 +397,8 @@ void QBluetoothLocalDevice::requestPairing(const QBluetoothAddress &address, Pai QStringLiteral("NoInputNoOutput")); QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, this); - connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher *)), d_ptr, - SLOT(pairingCompleted(QDBusPendingCallWatcher *))); + connect(watcher, &QDBusPendingCallWatcher::finished, + d_ptr, &QBluetoothLocalDevicePrivate::pairingCompleted); if (reply.isError()) qCWarning(QT_BT_BLUEZ) << Q_FUNC_INFO << reply.error() << d_ptr->agent_path; @@ -492,8 +492,8 @@ void QBluetoothLocalDevicePrivate::requestPairingBluez5(const QBluetoothAddress pairingDiscoveryTimer = new QTimer(this); pairingDiscoveryTimer->setSingleShot(true); pairingDiscoveryTimer->setInterval(20000); //20s - connect(pairingDiscoveryTimer, SIGNAL(timeout()), - SLOT(pairingDiscoveryTimedOut())); + connect(pairingDiscoveryTimer, &QTimer::timeout, + this, &QBluetoothLocalDevicePrivate::pairingDiscoveryTimedOut); } qCDebug(QT_BT_BLUEZ) << "Initiating discovery for pairing on" << targetAddress.toString(); @@ -555,8 +555,8 @@ void QBluetoothLocalDevicePrivate::processPairingBluez5(const QString &objectPat //initiate the pairing QDBusPendingReply<> pairReply = pairingTarget->Pair(); QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pairReply, this); - connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), - SLOT(pairingCompleted(QDBusPendingCallWatcher*))); + connect(watcher, &QDBusPendingCallWatcher::finished, + this, &QBluetoothLocalDevicePrivate::pairingCompleted); return; } @@ -678,12 +678,12 @@ void QBluetoothLocalDevicePrivate::connectDeviceChanges() { if (adapter) { // invalid QBluetoothLocalDevice due to wrong local adapter address createCache(); - connect(adapter, SIGNAL(PropertyChanged(QString, QDBusVariant)), - SLOT(PropertyChanged(QString, QDBusVariant))); - connect(adapter, SIGNAL(DeviceCreated(QDBusObjectPath)), - SLOT(_q_deviceCreated(QDBusObjectPath))); - connect(adapter, SIGNAL(DeviceRemoved(QDBusObjectPath)), - SLOT(_q_deviceRemoved(QDBusObjectPath))); + connect(adapter, &OrgBluezAdapterInterface::PropertyChanged, + this, &QBluetoothLocalDevicePrivate::PropertyChanged); + connect(adapter, &OrgBluezAdapterInterface::DeviceCreated, + this, &QBluetoothLocalDevicePrivate::_q_deviceCreated); + connect(adapter, &OrgBluezAdapterInterface::DeviceRemoved, + this, &QBluetoothLocalDevicePrivate::_q_deviceRemoved); } else if (adapterBluez5 && managerBluez5) { //setup property change notifications for all existing devices QDBusPendingReply<ManagedObjectList> reply = managerBluez5->GetManagedObjects(); @@ -710,8 +710,8 @@ void QBluetoothLocalDevicePrivate::connectDeviceChanges() monitor = new OrgFreedesktopDBusPropertiesInterface(QStringLiteral("org.bluez"), path.path(), QDBusConnection::systemBus(), this); - connect(monitor, SIGNAL(PropertiesChanged(QString,QVariantMap,QStringList)), - SLOT(PropertiesChanged(QString,QVariantMap,QStringList))); + connect(monitor, &OrgFreedesktopDBusPropertiesInterface::PropertiesChanged, + this, &QBluetoothLocalDevicePrivate::PropertiesChanged); deviceChangeMonitors.insert(path.path(), monitor); if (ifaceValues.value(QStringLiteral("Connected"), false).toBool()) { @@ -788,13 +788,13 @@ void QBluetoothLocalDevicePrivate::initializeAdapter() // monitor case when local adapter is removed manager = man.take(); - connect(manager, SIGNAL(AdapterRemoved(QDBusObjectPath)), - this, SLOT(adapterRemoved(QDBusObjectPath))); + connect(manager, &OrgBluezManagerInterface::AdapterRemoved, + this, &QBluetoothLocalDevicePrivate::adapterRemoved); currentMode = static_cast<QBluetoothLocalDevice::HostMode>(-1); if (adapter) { - connect(adapter, SIGNAL(PropertyChanged(QString, QDBusVariant)), - SLOT(PropertyChanged(QString, QDBusVariant))); + connect(adapter, &OrgBluezAdapterInterface::PropertyChanged, + this, &QBluetoothLocalDevicePrivate::PropertyChanged); agent_path = agentPath; agent_path.append(QString::fromLatin1("/%1").arg(QRandomGenerator::global()->generate())); @@ -813,10 +813,10 @@ void QBluetoothLocalDevicePrivate::initializeAdapterBluez5() QStringLiteral("/"), QDBusConnection::systemBus(), this); - connect(managerBluez5, SIGNAL(InterfacesAdded(QDBusObjectPath,InterfaceList)), - SLOT(InterfacesAdded(QDBusObjectPath,InterfaceList))); - connect(managerBluez5, SIGNAL(InterfacesRemoved(QDBusObjectPath,QStringList)), - SLOT(InterfacesRemoved(QDBusObjectPath,QStringList))); + connect(managerBluez5, &OrgFreedesktopDBusObjectManagerInterface::InterfacesAdded, + this, &QBluetoothLocalDevicePrivate::InterfacesAdded); + connect(managerBluez5, &OrgFreedesktopDBusObjectManagerInterface::InterfacesRemoved, + this, &QBluetoothLocalDevicePrivate::InterfacesRemoved); bool ok = true; const QString adapterPath = findAdapterForAddress(localAddress, &ok); @@ -833,8 +833,8 @@ void QBluetoothLocalDevicePrivate::initializeAdapterBluez5() adapterProperties = new OrgFreedesktopDBusPropertiesInterface( QStringLiteral("org.bluez"), adapterBluez5->path(), QDBusConnection::systemBus(), this); - connect(adapterProperties, SIGNAL(PropertiesChanged(QString,QVariantMap,QStringList)), - SLOT(PropertiesChanged(QString,QVariantMap,QStringList))); + connect(adapterProperties, &OrgFreedesktopDBusPropertiesInterface::PropertiesChanged, + this, &QBluetoothLocalDevicePrivate::PropertiesChanged); } currentMode = static_cast<QBluetoothLocalDevice::HostMode>(-1); @@ -914,8 +914,8 @@ void QBluetoothLocalDevicePrivate::InterfacesAdded(const QDBusObjectPath &object QStringLiteral("org.bluez"), object_path.path(), QDBusConnection::systemBus()); - connect(monitor, SIGNAL(PropertiesChanged(QString,QVariantMap,QStringList)), - SLOT(PropertiesChanged(QString,QVariantMap,QStringList))); + connect(monitor, &OrgFreedesktopDBusPropertiesInterface::PropertiesChanged, + this, &QBluetoothLocalDevicePrivate::PropertiesChanged); deviceChangeMonitors.insert(object_path.path(), monitor); const QVariantMap ifaceValues = interfaces_and_properties.value(QStringLiteral("org.bluez.Device1")); @@ -1034,8 +1034,8 @@ void QBluetoothLocalDevicePrivate::_q_deviceCreated(const QDBusObjectPath &devic = new OrgBluezDeviceInterface(QStringLiteral("org.bluez"), device.path(), QDBusConnection::systemBus(), this); - connect(deviceInterface, SIGNAL(PropertyChanged(QString, QDBusVariant)), - SLOT(_q_devicePropertyChanged(QString, QDBusVariant))); + connect(deviceInterface, &OrgBluezDeviceInterface::PropertyChanged, + this, &QBluetoothLocalDevicePrivate::_q_devicePropertyChanged); devices << deviceInterface; QDBusPendingReply<QVariantMap> properties = deviceInterface->asyncCall(QStringLiteral("GetProperties")); @@ -1112,8 +1112,8 @@ void QBluetoothLocalDevicePrivate::createCache() new OrgBluezDeviceInterface(QStringLiteral("org.bluez"), device.path(), QDBusConnection::systemBus(), this); - connect(deviceInterface, SIGNAL(PropertyChanged(QString,QDBusVariant)), - SLOT(_q_devicePropertyChanged(QString,QDBusVariant))); + connect(deviceInterface, &OrgBluezDeviceInterface::PropertyChanged, + this, &QBluetoothLocalDevicePrivate::_q_devicePropertyChanged); devices << deviceInterface; QDBusPendingReply<QVariantMap> properties diff --git a/src/bluetooth/qbluetoothserver.h b/src/bluetooth/qbluetoothserver.h index 193101fc..5e71b58c 100644 --- a/src/bluetooth/qbluetoothserver.h +++ b/src/bluetooth/qbluetoothserver.h @@ -104,10 +104,6 @@ protected: private: Q_DECLARE_PRIVATE(QBluetoothServer) - -#if QT_CONFIG(bluez) - Q_PRIVATE_SLOT(d_func(), void _q_newConnection()) -#endif }; QT_END_NAMESPACE diff --git a/src/bluetooth/qbluetoothserver_bluez.cpp b/src/bluetooth/qbluetoothserver_bluez.cpp index 100c2bec..f45aee28 100644 --- a/src/bluetooth/qbluetoothserver_bluez.cpp +++ b/src/bluetooth/qbluetoothserver_bluez.cpp @@ -252,7 +252,10 @@ bool QBluetoothServer::listen(const QBluetoothAddress &address, quint16 port) if (!d->socketNotifier) { d->socketNotifier = new QSocketNotifier(d->socket->socketDescriptor(), QSocketNotifier::Read); - connect(d->socketNotifier, SIGNAL(activated(int)), this, SLOT(_q_newConnection())); + connect(d->socketNotifier, &QSocketNotifier::activated, + [d](){ + d->_q_newConnection(); + }); } return true; diff --git a/src/bluetooth/qbluetoothservicediscoveryagent.cpp b/src/bluetooth/qbluetoothservicediscoveryagent.cpp index 8f4aa68b..3260d7db 100644 --- a/src/bluetooth/qbluetoothservicediscoveryagent.cpp +++ b/src/bluetooth/qbluetoothservicediscoveryagent.cpp @@ -434,13 +434,19 @@ void QBluetoothServiceDiscoveryAgentPrivate::startDeviceDiscovery() #else deviceDiscoveryAgent = new QBluetoothDeviceDiscoveryAgent(q); #endif - QObject::connect(deviceDiscoveryAgent, SIGNAL(finished()), - q, SLOT(_q_deviceDiscoveryFinished())); - QObject::connect(deviceDiscoveryAgent, SIGNAL(deviceDiscovered(QBluetoothDeviceInfo)), - q, SLOT(_q_deviceDiscovered(QBluetoothDeviceInfo))); - QObject::connect(deviceDiscoveryAgent, SIGNAL(error(QBluetoothDeviceDiscoveryAgent::Error)), - q, SLOT(_q_deviceDiscoveryError(QBluetoothDeviceDiscoveryAgent::Error))); - + QObject::connect(deviceDiscoveryAgent, &QBluetoothDeviceDiscoveryAgent::finished, + [this](){ + this->_q_deviceDiscoveryFinished(); + }); + QObject::connect(deviceDiscoveryAgent, &QBluetoothDeviceDiscoveryAgent::deviceDiscovered, + [this](const QBluetoothDeviceInfo &info){ + this->_q_deviceDiscovered(info); + }); + QObject::connect(deviceDiscoveryAgent, + QOverload<QBluetoothDeviceDiscoveryAgent::Error>::of(&QBluetoothDeviceDiscoveryAgent::error), + [this](QBluetoothDeviceDiscoveryAgent::Error newError){ + this->_q_deviceDiscoveryError(newError); + }); } setDiscoveryState(DeviceDiscovery); diff --git a/src/bluetooth/qbluetoothservicediscoveryagent.h b/src/bluetooth/qbluetoothservicediscoveryagent.h index 4a553c7d..1db05f55 100644 --- a/src/bluetooth/qbluetoothservicediscoveryagent.h +++ b/src/bluetooth/qbluetoothservicediscoveryagent.h @@ -110,25 +110,6 @@ Q_SIGNALS: private: QBluetoothServiceDiscoveryAgentPrivate *d_ptr; - - - Q_PRIVATE_SLOT(d_func(), void _q_deviceDiscovered(const QBluetoothDeviceInfo &info)) - Q_PRIVATE_SLOT(d_func(), void _q_deviceDiscoveryFinished()) - Q_PRIVATE_SLOT(d_func(), void _q_deviceDiscoveryError(QBluetoothDeviceDiscoveryAgent::Error)) - Q_PRIVATE_SLOT(d_func(), void _q_serviceDiscoveryFinished()) - -#if QT_CONFIG(bluez) - Q_PRIVATE_SLOT(d_func(), void _q_discoveredServices(QDBusPendingCallWatcher*)) - Q_PRIVATE_SLOT(d_func(), void _q_createdDevice(QDBusPendingCallWatcher*)) - Q_PRIVATE_SLOT(d_func(), void _q_foundDevice(QDBusPendingCallWatcher*)) - Q_PRIVATE_SLOT(d_func(), void _q_sdpScannerDone(int,QProcess::ExitStatus)) -#endif -#ifdef QT_ANDROID_BLUETOOTH - Q_PRIVATE_SLOT(d_func(), void _q_processFetchedUuids(const QBluetoothAddress &address, - const QList<QBluetoothUuid>&)) - Q_PRIVATE_SLOT(d_func(), void _q_fetchUuidsTimeout()) - Q_PRIVATE_SLOT(d_func(), void _q_hostModeStateChanged(QBluetoothLocalDevice::HostMode state)) -#endif }; QT_END_NAMESPACE diff --git a/src/bluetooth/qbluetoothservicediscoveryagent_android.cpp b/src/bluetooth/qbluetoothservicediscoveryagent_android.cpp index d6e43cd7..ac2b1906 100644 --- a/src/bluetooth/qbluetoothservicediscoveryagent_android.cpp +++ b/src/bluetooth/qbluetoothservicediscoveryagent_android.cpp @@ -37,6 +37,7 @@ ** ****************************************************************************/ +#include <QtCore/qcoreapplication.h> #include <QtCore/QLoggingCategory> #include <QtCore/QTimer> #include <QtCore/private/qjnihelpers_p.h> @@ -198,14 +199,18 @@ void QBluetoothServiceDiscoveryAgentPrivate::start(const QBluetoothAddress &addr //Full discovery uses BluetoothDevice.fetchUuidsWithSdp() if (!receiver) { receiver = new ServiceDiscoveryBroadcastReceiver(); - QObject::connect(receiver, SIGNAL(uuidFetchFinished(QBluetoothAddress,QList<QBluetoothUuid>)), - q, SLOT(_q_processFetchedUuids(QBluetoothAddress,QList<QBluetoothUuid>))); + QObject::connect(receiver, &ServiceDiscoveryBroadcastReceiver::uuidFetchFinished, + [this](const QBluetoothAddress &address, const QList<QBluetoothUuid>& uuids) { + this->_q_processFetchedUuids(address, uuids); + }); } if (!localDeviceReceiver) { localDeviceReceiver = new LocalDeviceBroadcastReceiver(); - QObject::connect(localDeviceReceiver, SIGNAL(hostModeStateChanged(QBluetoothLocalDevice::HostMode)), - q, SLOT(_q_hostModeStateChanged(QBluetoothLocalDevice::HostMode))); + QObject::connect(localDeviceReceiver, &LocalDeviceBroadcastReceiver::hostModeStateChanged, + [this](QBluetoothLocalDevice::HostMode state){ + this->_q_hostModeStateChanged(state); + }); } jboolean result = remoteDevice.callMethod<jboolean>("fetchUuidsWithSdp"); @@ -245,8 +250,9 @@ 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) { - Q_Q(QBluetoothServiceDiscoveryAgent); - QTimer::singleShot(4000, q, SLOT(_q_fetchUuidsTimeout())); + QTimer::singleShot(4000, qApp, [this]() { + this->_q_fetchUuidsTimeout(); + }); } _q_serviceDiscoveryFinished(); return; @@ -295,8 +301,9 @@ 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) { - Q_Q(QBluetoothServiceDiscoveryAgent); - QTimer::singleShot(4000, q, SLOT(_q_fetchUuidsTimeout())); + QTimer::singleShot(4000, qApp, [this]() { + this->_q_fetchUuidsTimeout(); + }); return; } diff --git a/src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp b/src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp index 1f609428..dbd084ed 100644 --- a/src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp +++ b/src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp @@ -128,8 +128,10 @@ void QBluetoothServiceDiscoveryAgentPrivate::start(const QBluetoothAddress &addr QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(deviceObjectPath, q); watcher->setProperty("_q_BTaddress", QVariant::fromValue(address)); - QObject::connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), - q, SLOT(_q_foundDevice(QDBusPendingCallWatcher*))); + QObject::connect(watcher, &QDBusPendingCallWatcher::finished, + [this](QDBusPendingCallWatcher *watcher){ + this->_q_foundDevice(watcher); + }); } // Bluez 5 @@ -212,8 +214,11 @@ void QBluetoothServiceDiscoveryAgentPrivate::runExternalSdpScan( if (QT_BT_BLUEZ().isDebugEnabled()) sdpScannerProcess->setProcessChannelMode(QProcess::ForwardedErrorChannel); sdpScannerProcess->setProgram(fileInfo.canonicalFilePath()); - q->connect(sdpScannerProcess, SIGNAL(finished(int,QProcess::ExitStatus)), - q, SLOT(_q_sdpScannerDone(int,QProcess::ExitStatus))); + q->connect(sdpScannerProcess, + QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished), + [this](int exitCode, QProcess::ExitStatus status){ + this->_q_sdpScannerDone(exitCode, status); + }); } QStringList arguments; @@ -326,7 +331,7 @@ void QBluetoothServiceDiscoveryAgentPrivate::stop() { qCDebug(QT_BT_BLUEZ) << Q_FUNC_INFO << "Stop called"; if (device) { - //we are waiting for _q_discoveredServices() slot to be called + //we are waiting for _q_discoveredServices() to be called // adapter is already 0 QDBusPendingReply<> reply = device->CancelDiscovery(); reply.waitForFinished(); @@ -335,7 +340,7 @@ void QBluetoothServiceDiscoveryAgentPrivate::stop() device = nullptr; Q_ASSERT(!adapter); } else if (adapter) { - //we are waiting for _q_createdDevice() slot to be called + //we are waiting for _q_createdDevice() to be called adapter->deleteLater(); adapter = nullptr; Q_ASSERT(!device); @@ -390,8 +395,11 @@ void QBluetoothServiceDiscoveryAgentPrivate::_q_foundDevice(QDBusPendingCallWatc deviceObjectPath = adapter->CreateDevice(address.toString()); watcher = new QDBusPendingCallWatcher(deviceObjectPath, q); watcher->setProperty("_q_BTaddress", QVariant::fromValue(address)); - QObject::connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), - q, SLOT(_q_createdDevice(QDBusPendingCallWatcher*))); + QObject::connect(watcher, &QDBusPendingCallWatcher::finished, + [this](QDBusPendingCallWatcher *watcher){ + this->_q_createdDevice(watcher); + }); + return; } @@ -528,8 +536,10 @@ void QBluetoothServiceDiscoveryAgentPrivate::discoverServices(const QString &dev QDBusPendingReply<ServiceMap> discoverReply = device->DiscoverServices(pattern); QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(discoverReply, q); - QObject::connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), - q, SLOT(_q_discoveredServices(QDBusPendingCallWatcher*))); + QObject::connect(watcher, &QDBusPendingCallWatcher::finished, + [this](QDBusPendingCallWatcher *watcher){ + this->_q_discoveredServices(watcher); + }); } } -- GitLab