Lorne Sturtevant
12th April 2012, 18:50
I'm trying use QDBusConnection::asyncCall() but it is not working correctly. I make the call and the server receives it and sends back a reply. I use a QDBusPendingCallWatcher to listen for the reply. The finished() signal of the watcher does not get called unless I tell the watcher to waitForFinished(). This defeats the entire purpose of using the asyncCall() since waitForFinished() blocks. Here's an example of what I'm doing. This is based on the example code in the QDBusPendingCallWatcher API documentation.
void Controller::makeCall() {
QDBusMessage msg = QDBusMessage::createMethodCall(serviceName, objectPath, "", method);
QDBusPendingCall asyncCall = connection.asyncCall(msg, timeout);
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(asyncCall, this);
QObject::connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)),
this, SLOT(callFinishedSlot(QDBusPendingCallWatcher*)));
// with this commented out, callFinishedSlot() is never called. If the comment is removed, callFinishedSlot() is called
//watcher->waitForFinished();
}
void Controller::callFinishedSlot(QDBusPendingCallWatch er *watcher) {
LOG_DEBUG("got finished");
} // callFinishedSlot()
I've also tried to do the same thing using QDBusInterface::asyncCall() instead of using QDBusConnection::asyncCall(), but I get the same result. The call to watcher->waitForFinished() is required to get a result.
void Controller::makeCall() {
QDBusMessage msg = QDBusMessage::createMethodCall(serviceName, objectPath, "", method);
QDBusPendingCall asyncCall = connection.asyncCall(msg, timeout);
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(asyncCall, this);
QObject::connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)),
this, SLOT(callFinishedSlot(QDBusPendingCallWatcher*)));
// with this commented out, callFinishedSlot() is never called. If the comment is removed, callFinishedSlot() is called
//watcher->waitForFinished();
}
void Controller::callFinishedSlot(QDBusPendingCallWatch er *watcher) {
LOG_DEBUG("got finished");
} // callFinishedSlot()
I've also tried to do the same thing using QDBusInterface::asyncCall() instead of using QDBusConnection::asyncCall(), but I get the same result. The call to watcher->waitForFinished() is required to get a result.