Results 1 to 5 of 5

Thread: Problem with asyncCall in DBus

  1. #1
    Join Date
    Apr 2012
    Posts
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Problem with asyncCall in DBus

    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.

    Qt Code:
    1. void Controller::makeCall() {
    2.  
    3. QDBusMessage msg = QDBusMessage::createMethodCall(serviceName, objectPath, "", method);
    4. QDBusPendingCall asyncCall = connection.asyncCall(msg, timeout);
    5.  
    6. QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(asyncCall, this);
    7. QObject::connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)),
    8. this, SLOT(callFinishedSlot(QDBusPendingCallWatcher*)));
    9.  
    10. // with this commented out, callFinishedSlot() is never called. If the comment is removed, callFinishedSlot() is called
    11. //watcher->waitForFinished();
    12. }
    13.  
    14. void Controller::callFinishedSlot(QDBusPendingCallWatcher *watcher) {
    15.  
    16. LOG_DEBUG("got finished");
    17. } // callFinishedSlot()
    To copy to clipboard, switch view to plain text mode 

    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.

  2. #2
    Join Date
    Jan 2014
    Posts
    3
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Problem with asyncCall in DBus

    I am not sure, but some sources says that your asynchronous call can finish before you actually connect to a slot. You can try cover your asynchronous method and signal/slot connection in debug messages to check if it is actually the case.

    I failed to find any proof or disproof of this problem in QT documentation.

  3. #3
    Join Date
    Jan 2014
    Posts
    3
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Problem with asyncCall in DBus

    Quote from http://www.qtdeveloperdays.com/north...-qt-5-and-c11:
    Pending objects such as QDBusPendingCallWatcher might finish processing before connecting to a slot.
    Link has presentation attached with this aproach:
    Qt Code:
    1. QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(jobPath);
    2. if (watcher->isFinished()) {
    3. onJobPathFinished(watcher)
    4. } else {
    5. connect(watcher, &QDBusPendingCallWatcher::finished, onJobPathFinished);
    6. }
    To copy to clipboard, switch view to plain text mode 

    But again I am not sure if this aproach garantee that connection to a slot will finish before DBus call finishes.

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Problem with asyncCall in DBus

    Quote Originally Posted by galap View Post
    I am not sure, but some sources says that your asynchronous call can finish before you actually connect to a slot.
    Only if you return to the event loop or explicitly cause event processing in between.

    Without event processing there is no way for the reply to be read from the D-Bus connection socket.

    Cheers,
    _

    P.S.: the thread is almost two years old

  5. #5
    Join Date
    Jan 2014
    Posts
    3
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Problem with asyncCall in DBus

    Good to know. Makes me more relaxed . But original case is unresolved anyway. The only thing that cross my mind - mainloop and posted hadler run in different threads.
    Thanks for help anyway!

    --
    P.S.: Was forced to use pending call watcher only last week and this question took place.

Similar Threads

  1. Replies: 1
    Last Post: 17th November 2010, 13:58
  2. need DBus help
    By nrabara in forum Newbie
    Replies: 2
    Last Post: 2nd May 2009, 07:41
  3. DBus Registration problem
    By nrabara in forum Newbie
    Replies: 1
    Last Post: 30th April 2009, 10:34
  4. Qt 4.5.0 win opensource and <dbus/dbus.h>
    By YaK in forum Installation and Deployment
    Replies: 2
    Last Post: 22nd March 2009, 11:06
  5. DBus and IPC
    By DrDonut in forum Qt Programming
    Replies: 3
    Last Post: 22nd March 2008, 23:42

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.