Uploaded image for project: 'Qt for Python'
  1. Qt for Python
  2. PYSIDE-2547

Receiving DBus signal doesn't work

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • Not Evaluated
    • None
    • 6.6.1
    • PySide
    • None
    • Ubuntu 22.04 LTS
      Python 3.10.12
    • Linux/Wayland, Linux/X11
    • 2c3bf4273 (dev), ead40ef99 (6.6), 8f984a8a6 (tqtc/lts-6.5), a8fcf4414 (dev)

    Description

      Hello,

      I am trying to connect to a DBus Signal with PySide6, but don't get it to work and wonder if the signature stated in the docs is really correct.

      I am trying to get a notification, when a new service name is on the system DBus...

       

      import sysfrom PySide6 import QtDBus
      from PySide6.QtCore import QLibraryInfo, qVersion
      from PySide6.QtWidgets import QApplication, QMainWindow
      
      class MainWindow(QMainWindow):
          def __init__ (self, *args, **kwargs):
              super().__init__(*args, **kwargs)
              service = 'org.freedesktop.DBus'
              path = '/org/freedesktop/DBus'
              iface = 'org.freedesktop.DBus'
              conn = QtDBus.QDBusConnection.systemBus()
              #conn.connect(service, path, iface, "NameOwnerChanged", self.nameownerchangeslot, "nameownerchangeslot")
              #this brings up:
              #TypeError: 'PySide6.QtDBus.QDBusConnection.connect' called with wrong argument types:
              #PySide6.QtDBus.QDBusConnection.connect(str, str, str, str, method, str)
              conn.connect(service, path, iface, "NameOwnerChanged", self, "nameownerchangeslot")
      
          def nameownerchangeslot(self, arg:object) -> None:
              print(arg)
              pass
      
      if __name__ == '__main__':
          print('Python {}.{}.{} {}'.format(sys.version_info[0], sys.version_info[1],
                                             sys.version_info[2], sys.platform))
          print(QLibraryInfo.build())
          app = QApplication(sys.argv)
          window = MainWindow()
          window.setWindowTitle(qVersion())
          window.resize(800, 480)
          window.show()
          sys.exit(app.exec())
      

       
      This is the output:
       

      Python 3.10.12 linux
      Qt 6.6.1 (x86_64-little_endian-lp64 shared (dynamic) release build; by GCC 10.3.1 20210422 (Red Hat 10.3.1-1)) [Python limited API 3.10.12]
      qt.dbus.integration: Could not connect "org.freedesktop.DBus" to ameownerchangeslot : 

      The receiver is defined as QObject and the slot as a str, on a normal python signal connect, this is simply an object.

      You see also if i pass the method as argument it is complaining that it is not on object, but also on a normal python signal connect, the argument is also defined as object and giving the method works...

      I also tried an external package like sdbus, but this needs the asyncio package to listen for signals. I also configured PySide to use the asyncio loop, but the event class hasn't implemented the file watchers and socket connections, so this doesn't work either...

      Any help and clarification is appreciated!

      Best regards
      Matthias Nacke

       

       
      {{}}

      Attachments

        1. dbusoutput.png
          dbusoutput.png
          510 kB
        2. d-feet.png
          d-feet.png
          229 kB
        3. dfeetproperties.png
          dfeetproperties.png
          82 kB
        4. pyside2547_cpp.zip
          1 kB
        5. pyside2547.py
          2 kB
        6. qdbusdemo.py
          1 kB
        7. qdbusdemo-upd-20231212-1509.py
          1 kB
        8. qdbusdemo-upd-20231212-1715.py
          1 kB
        9. qdbusdemo-upd-20231212-2052.py
          2 kB
        10. qdbusdemo-upd-20231214-0926.py
          2 kB
        11. qdbusdemo-upd-20231214-1320.py
          2 kB
        For Gerrit Dashboard: PYSIDE-2547
        # Subject Branch Project Status CR V

        Activity

          People

            adherrma Adrian Herrmann
            drexel M N
            M N M N
            M N M N
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There is 1 open Gerrit change