diff options
-rw-r--r-- | src/bluetooth/qbluetoothsocket_bluezdbus.cpp | 21 | ||||
-rw-r--r-- | src/bluetooth/qbluetoothsocket_bluezdbus_p.h | 4 |
2 files changed, 20 insertions, 5 deletions
diff --git a/src/bluetooth/qbluetoothsocket_bluezdbus.cpp b/src/bluetooth/qbluetoothsocket_bluezdbus.cpp index f56abfba..3ce7e8b6 100644 --- a/src/bluetooth/qbluetoothsocket_bluezdbus.cpp +++ b/src/bluetooth/qbluetoothsocket_bluezdbus.cpp @@ -238,18 +238,29 @@ void QBluetoothSocketPrivateBluezDBus::connectToServiceHelper( OrgBluezDevice1Interface device(QStringLiteral("org.bluez"), remoteDevicePath, QDBusConnection::systemBus()); reply = device.ConnectProfile(profileUuid); + QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, this); + connect(watcher, &QDBusPendingCallWatcher::finished, + this, &QBluetoothSocketPrivateBluezDBus::connectToServiceReplyHandler); + + q->setOpenMode(openMode); + q->setSocketState(QBluetoothSocket::ConnectingState); +} + +void QBluetoothSocketPrivateBluezDBus::connectToServiceReplyHandler( + QDBusPendingCallWatcher *watcher) +{ + Q_Q(QBluetoothSocket); + + QDBusPendingReply<> reply = *watcher; if (reply.isError()) { - qCWarning(QT_BT_BLUEZ) << "Cannot connect to profile/service:" << uuid; + qCWarning(QT_BT_BLUEZ) << "Cannot connect to profile/service."; clearSocket(); errorString = QBluetoothSocket::tr("Cannot connect to remote profile"); q->setSocketError(QBluetoothSocket::HostNotFoundError); - return; } - - q->setOpenMode(openMode); - q->setSocketState(QBluetoothSocket::ConnectingState); + watcher->deleteLater(); } void QBluetoothSocketPrivateBluezDBus::connectToService( diff --git a/src/bluetooth/qbluetoothsocket_bluezdbus_p.h b/src/bluetooth/qbluetoothsocket_bluezdbus_p.h index 383c9fcb..deedf916 100644 --- a/src/bluetooth/qbluetoothsocket_bluezdbus_p.h +++ b/src/bluetooth/qbluetoothsocket_bluezdbus_p.h @@ -56,6 +56,7 @@ #include <QtDBus/qdbusunixfiledescriptor.h> #include <QtNetwork/qlocalsocket.h> +#include <QDBusPendingCallWatcher> class OrgBluezProfileManager1Interface; @@ -110,6 +111,9 @@ public: bool canReadLine() const override; qint64 bytesToWrite() const override; +public slots: + void connectToServiceReplyHandler(QDBusPendingCallWatcher *); + private: void remoteConnected(const QDBusUnixFileDescriptor &fd); void socketStateChanged(QLocalSocket::LocalSocketState newState); |