Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8385149
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:35:47+00:00 2026-06-09T17:35:47+00:00

I’d like to make a non-blocking call to a function in a remote D-Bus

  • 0

I’d like to make a non-blocking call to a function in a remote D-Bus service using PyQt4.QtDBus. Adapting from Qt’s C++ documentation, I came up with the following test program:

from PyQt4 import QtCore, QtDBus

class DeviceInterface(QtDBus.QDBusAbstractInterface):

    def __init__(self, service, path, connection, parent=None):
        super().__init__(service, path, 'org.freedesktop.UDisks.Device',
                         connection, parent)

    @QtCore.pyqtSlot(QtDBus.QDBusArgument)
    def callFinishedSlot(self, arg):
        print("Got result:", arg)


if __name__ == '__main__':
    import sys
    app = QtCore.QCoreApplication(sys.argv)

    dev = DeviceInterface('org.freedesktop.UDisks',
                          '/org/freedesktop/UDisks/devices/sda1',
                          QtDBus.QDBusConnection.systemBus(), app)

    async = dev.asyncCall("FilesystemListOpenFiles");
    watcher = QtDBus.QDBusPendingCallWatcher(async, dev)
    watcher.finished.connect(dev.callFinishedSlot)
    sys.exit(app.exec_())

It seems to work. When I run it, it prints:

Got result: <PyQt4.QtDBus.QDBusPendingCallWatcher object at 0xb740c77c>

The problem is, I don’t know how to convert the QDBusPendingCallWatcher to something (e.g., QDBusMessage) that I can extract the results from. The example from the C++ documentation does this:

 void MyClass.callFinishedSlot(QDBusPendingCallWatcher *call)
 {
     QDBusPendingReply<QString, QByteArray> reply = *call;
     if (reply.isError()) {
         showError();
     } else {
         QString text = reply.argumentAt<0>();
         QByteArray data = reply.argumentAt<1>();
         showReply(text, data);
     }
     call->deleteLater();
 }

Can anyone tell me how to translate the C++ slot to something that will work with PyQt4? (I’m using PyQt4.9.1 with Qt 4.8.1.)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T17:35:49+00:00Added an answer on June 9, 2026 at 5:35 pm

    Okay, the trick seems to be to construct a QDBusPendingReply from the QDBusPendingCallWatcher instance (many thanks to Phil Thompson for pointing this out on the PyQt mailing list). As it turns out, this same technique also works in C++. I had the UDisk object path wrong in my original code, plus a few other minor typos, so here’s a complete, working example for posterity:

    from PyQt4 import QtCore, QtDBus
    
    class DeviceInterface(QtDBus.QDBusAbstractInterface):
    
        def __init__(self, service, path, connection, parent=None):
            super().__init__(service, path, 'org.freedesktop.UDisks.Device',
                             connection, parent)
    
        def callFinishedSlot(self, call):
            # Construct a reply object from the QDBusPendingCallWatcher
            reply = QtDBus.QDBusPendingReply(call)
            if reply.isError():
                print(reply.error().message())
            else:
                print("  PID        UID     COMMAND")
                print("-------    -------   ------------------------------------")
                for pid, uid, cmd in reply.argumentAt(0):
                    print("{0:>7d}    {1:>7d}   {2}".format(pid, uid, cmd))
            # Important: Tell Qt we are finished processing this message
            call.deleteLater()
    
    if __name__ == '__main__':
        import sys
        import signal
        signal.signal(signal.SIGINT, signal.SIG_DFL)
    
        app = QtCore.QCoreApplication(sys.argv)
    
        dev = DeviceInterface('org.freedesktop.UDisks',
                              '/org/freedesktop/UDisks/devices/sda1',
                              QtDBus.QDBusConnection.systemBus(), app)
    
        async = dev.asyncCall("FilesystemListOpenFiles");
        watcher = QtDBus.QDBusPendingCallWatcher(async, dev)
        watcher.finished.connect(dev.callFinishedSlot)
        sys.exit(app.exec_())
    

    This should work on most recent Linux distros, and is a good example of using PyQt to invoke a D-Bus method that returns a compound type.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I would like to count the length of a string with PHP. The string
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I am reading a book about Javascript and jQuery and using one of the
I would like to run a str_replace or preg_replace which looks for certain words
I am trying to render a haml file in a javascript response like so:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.