diff options
Diffstat (limited to 'src/dbus/qdbuspendingcall.cpp')
-rw-r--r-- | src/dbus/qdbuspendingcall.cpp | 59 |
1 files changed, 34 insertions, 25 deletions
diff --git a/src/dbus/qdbuspendingcall.cpp b/src/dbus/qdbuspendingcall.cpp index 814cfa06b2..f9d414d1bd 100644 --- a/src/dbus/qdbuspendingcall.cpp +++ b/src/dbus/qdbuspendingcall.cpp @@ -94,7 +94,8 @@ using namespace Qt::StringLiterals; void QDBusPendingCallWatcherHelper::add(QDBusPendingCallWatcher *watcher) { - connect(this, SIGNAL(finished()), watcher, SLOT(_q_finished()), Qt::QueuedConnection); + connect(this, &QDBusPendingCallWatcherHelper::finished, watcher, + [watcher] { Q_EMIT watcher->finished(watcher); }, Qt::QueuedConnection); } QDBusPendingCallPrivate::~QDBusPendingCallPrivate() @@ -123,22 +124,24 @@ bool QDBusPendingCallPrivate::setReplyCallback(QObject *target, const char *memb return false; } - methodIdx = QDBusConnectionPrivate::findSlot(target, member + 1, metaTypes); + QString errorMsg; + methodIdx = QDBusConnectionPrivate::findSlot(target, member + 1, metaTypes, errorMsg); if (methodIdx == -1) { QByteArray normalizedName = QMetaObject::normalizedSignature(member + 1); - methodIdx = QDBusConnectionPrivate::findSlot(target, normalizedName, metaTypes); + methodIdx = QDBusConnectionPrivate::findSlot(target, normalizedName, metaTypes, errorMsg); } if (methodIdx == -1) { // would not be able to deliver a reply - qWarning("QDBusPendingCall::setReplyCallback: error: cannot deliver a reply to %s::%s (%s)", - target->metaObject()->className(), - member + 1, qPrintable(target->objectName())); + qWarning("QDBusPendingCall::setReplyCallback: error: cannot deliver a reply to %s::%s (%s) " + "because %s", + target->metaObject()->className(), member + 1, qPrintable(target->objectName()), + qPrintable(errorMsg)); return false; } // success // construct the expected signature - int count = metaTypes.count() - 1; + int count = metaTypes.size() - 1; if (count == 1 && metaTypes.at(1) == QDBusMetaTypeId::message()) { // wildcard slot, can receive anything, so don't set the signature return true; @@ -203,6 +206,26 @@ void QDBusPendingCallPrivate::waitForFinished() waitForFinishedCondition.wait(&mutex); } +void QDBusPendingCallPrivate::waitForFinishedWithGui() +{ + QEventLoop loop; + + { + const auto locker = qt_scoped_lock(mutex); + if (replyMessage.type() != QDBusMessage::InvalidMessage) + return; // already finished + + Q_ASSERT(!watcherHelper); + watcherHelper = new QDBusPendingCallWatcherHelper; + loop.connect(watcherHelper, &QDBusPendingCallWatcherHelper::reply, &loop, + &QEventLoop::quit); + loop.connect(watcherHelper, &QDBusPendingCallWatcherHelper::error, &loop, + &QEventLoop::quit); + } + + loop.exec(QEventLoop::ExcludeUserInputEvents | QEventLoop::WaitForMoreEvents); +} + /*! Creates a copy of the \a other pending asynchronous call. Note that both objects will refer to the same pending call. @@ -221,7 +244,6 @@ QDBusPendingCall::QDBusPendingCall(QDBusPendingCallPrivate *dd) if (dd) { bool r = dd->ref.deref(); Q_ASSERT(r); - Q_UNUSED(r); } } @@ -443,28 +465,13 @@ QDBusPendingCall QDBusPendingCall::fromCompletedCall(const QDBusMessage &msg) return QDBusPendingCall(d); } - -class QDBusPendingCallWatcherPrivate: public QObjectPrivate -{ -public: - void _q_finished(); - - Q_DECLARE_PUBLIC(QDBusPendingCallWatcher) -}; - -inline void QDBusPendingCallWatcherPrivate::_q_finished() -{ - Q_Q(QDBusPendingCallWatcher); - emit q->finished(q); -} - /*! Creates a QDBusPendingCallWatcher object to watch for replies on the asynchronous pending call \a call and sets this object's parent to \a parent. */ QDBusPendingCallWatcher::QDBusPendingCallWatcher(const QDBusPendingCall &call, QObject *parent) - : QObject(*new QDBusPendingCallWatcherPrivate, parent), QDBusPendingCall(call) + : QObject(parent), QDBusPendingCall(call) { if (d) { // QDBusPendingCall::d const auto locker = qt_scoped_lock(d->mutex); @@ -472,7 +479,9 @@ QDBusPendingCallWatcher::QDBusPendingCallWatcher(const QDBusPendingCall &call, Q d->watcherHelper = new QDBusPendingCallWatcherHelper; if (d->replyMessage.type() != QDBusMessage::InvalidMessage) { // cause a signal emission anyways - QMetaObject::invokeMethod(d->watcherHelper, "finished", Qt::QueuedConnection); + QMetaObject::invokeMethod(d->watcherHelper, + &QDBusPendingCallWatcherHelper::finished, + Qt::QueuedConnection); } } d->watcherHelper->add(this); |