Details
-
Bug
-
Resolution: Duplicate
-
Not Evaluated
-
None
-
5.14.0, 5.14.1, 5.14.2
-
None
-
Python 3.7.5, PySide2 5.14.2 (official wheels)
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
- duplicates
-
PYSIDE-1898 QMetaObject.invokeMethod with arguments not possible
- Closed