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

Q_ARG missing, invokeMethod doesn't work currently with arguments in PySide2.

    XMLWordPrintable

Details

    • Bug
    • Resolution: Duplicate
    • Not Evaluated
    • None
    • 5.14.0, 5.14.1, 5.14.2
    • PySide
    • None
    • Python 3.7.5, PySide2 5.14.2 (official wheels)
    • Linux/Wayland, Linux/X11, macOS, Windows

    Description

      Q_ARG missing, invokeMethod doesn't work currently with arguments in PySide2.

       PyQt5

      import sys
      
      from PyQt5.QtCore import QObject, QMetaObject, QThread, pyqtSlot, Q_ARG
      from PyQt5.QtWidgets import QApplication
      
      
      class TestMeta(QObject):
          def __init__(self, parent=None):
              super().__init__(parent)
      
          @pyqtSlot(int)
          def method(self, name):
              print(f"Method is called with argument {name}")
              sys.exit(0)
      
      
      if __name__ == "__main__":
          app = QApplication(sys.argv)
          test_meta = TestMeta()
          thread = QThread()
          test_meta.moveToThread(thread)
          thread.start()
          QMetaObject.invokeMethod(test_meta, "method", Q_ARG('int', 12))
          sys.exit(app.exec_())
      

      Result

      Method is called with argument 12
      

       PySide2

      import sys
      
      from PySide2.QtCore import QObject, QMetaObject, QThread, Slot, QGenericArgument
      from PySide2.QtWidgets import QApplication
      
      
      class TestMeta(QObject):
          def __init__(self, parent=None):
              super().__init__(parent)
      
          @Slot(int)
          def method(self, name):
              print(f"Method is called with argument {name}")
              sys.exit(0)
      
      
      if __name__ == "__main__":
          app = QApplication(sys.argv)
          test_meta = TestMeta()
          thread = QThread()
          test_meta.moveToThread(thread)
          thread.start()
          QMetaObject.invokeMethod(test_meta, "method", QGenericArgument('int', 12))
          sys.exit(app.exec_())
      

      Error message

      QMetaObject.invokeMethod(test_meta, "method", QGenericArgument('int', 12))
      TypeError: 'PySide2.QtCore.QGenericArgument' called with wrong argument types:
        PySide2.QtCore.QGenericArgument(str, int)
      Supported signatures:
        PySide2.QtCore.QGenericArgument(PySide2.QtCore.QGenericArgument)
        PySide2.QtCore.QGenericArgument(typing.Union[bytes, NoneType] = None, typing.Union[int, NoneType] = None)
      

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              crmaurei Cristian Maureira-Fredes
              ideaplus ideaplus :-)
              Votes:
              4 Vote for this issue
              Watchers:
              8 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes