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

Missing QVariant/QMetaType API to specify type of QDBusArgument

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Unresolved
    • P3: Somewhat important
    • None
    • 6.3.0
    • PySide, Shiboken
    • None
    • Linux/X11

    Description

      On PySide6, the following code snippet:

      # from PyQt6.QtCore import QVariant, QMetaType
      # from PyQt6.QtWidgets import QApplication
      # from PyQt6.QtDBus import QDBusInterface, QDBusConnection, QDBus, QDBusMessage, QDBusArgument
      
      from PySide6.QtWidgets import QApplication
      from PySide6.QtDBus import QDBusInterface, QDBusConnection, QDBus, QDBusMessage
      
      SERVICE = "org.freedesktop.Notifications"
      PATH = "/org/freedesktop/Notifications"
      INTERFACE = SERVICE
      
      app = QApplication([])
      bus = QDBusConnection.sessionBus()
      iface = QDBusInterface(SERVICE, PATH, INTERFACE, bus)
      assert iface.isValid(), iface.lastError()
      
      def _as_uint32(x):
          # variant = QVariant(x)
          # successful = variant.convert(QMetaType(QMetaType.Type.UInt.value))
          # assert successful
          # return variant
          return x
      
      
      def _as_qstringlist(x):
          # return QDBusArgument(x, QMetaType.Type.QStringList.value)
          return x
      
      
      reply = iface.callWithArgumentList(
          QDBus.CallMode.Block,
          "Notify",
          [
              "test",  # app name
              _as_uint32(0),  # replaces_id
              "",  # icon filename
              "title",
              "body",
              _as_qstringlist([]),  # actions
              {},  # hints
              -1,  # timeout
          ]
      )
      assert reply.type() != QDBusMessage.MessageType.ErrorMessage, reply.errorMessage()
      print(reply.arguments())
      

      prints:

      AssertionError: Type of message, “(sisssasa{sv}i)”, does not match expected type “(susssasa{sv}i)”
      

      due to the freedesktop.org notification spec enforcing that replaces_id needs to be specified as UInt32 rather than Int32.

      With PyQt6, the commented out code can be used to explicitly pass a Python int as UInt32 to Qt (it otherwise handles QVariant transparently, like PySide does!). PySide6 seems to lack a similar mechanism, thus making it - from what I can see - impossible to use the notification API from it.

      As an aside: PyQt6 also seems to need some code so that the list of strings gets passed as that (as) rather than a list of variable objects (av). That seems unneeded with PySide6.

      Attachments

        1. pyside1904_cpp.zip
          1 kB
        2. pyside1904_pytqt.py
          2 kB
        3. pyside1904.py
          1 kB

        Issue Links

          For Gerrit Dashboard: PYSIDE-1904
          # Subject Branch Project Status CR V

          Activity

            People

              kleint Friedemann Kleint
              the compiler Florian Bruhin
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There is 1 open Gerrit change