Pyside6 Slot with Name arg crashes app
-
I use Pyside6 with QML and when calling the method "testMethod()" in QML using a button to call it, the app crashes with no error messages, just an instant close. But calling "test_method2()" in QML does no cause a crash and works fine.
As I know creating a signal on the class QObject like this this_sig = Signal(name="thisSig") works completely fine, so I assumed that would be the case for a Slot as well.Is the "name" arg in Slot simply bugged or not how I interprit its used as?
class Controller(QObject): def __init__( self, /, parent: QObject | None, ) -> None: super().__init__(parent) @Slot(name="testMethod", result=None) def test_method(self) -> None: print("test") @Slot(result=None) def test_method2(self) -> None: print("test")Button { text: "test" onClicked: Controller.testMethod() // This crashes } Button { text: "test2" onClicked: Controller.test_method2() // This works } -
Can you please provide a complete, minimal example that reproduces the crash (or report it as a bug (see https://wiki.qt.io/Qt_for_Python/Reporting_Bugs )?
-
Can you please provide a complete, minimal example that reproduces the crash (or report it as a bug (see https://wiki.qt.io/Qt_for_Python/Reporting_Bugs )?
@friedemannkleint Here is a complete minimal example that reproduces the issue.
Python (
main.py):import sys from PySide6.QtCore import QObject, Slot from PySide6.QtGui import QGuiApplication from PySide6.QtQml import QQmlApplicationEngine, QmlElement QML_IMPORT_NAME = "Example" QML_IMPORT_MAJOR_VERSION = 1 @QmlElement class Controller(QObject): def __init__( self, /, parent: QObject | None = None, ) -> None: super().__init__(parent) @Slot(name="testMethod", result=None) def test_method(self) -> None: print("test") @Slot(result=None) def test_method2(self) -> None: print("test") def main() -> None: app = QGuiApplication(sys.argv) engine = QQmlApplicationEngine() engine.loadFromModule("Example", "Main") if not engine.rootObjects(): sys.exit(-1) sys.exit(app.exec()) if __name__ == "__main__": main()QML (
Main.qml):import QtQuick import QtQuick.Controls import Example ApplicationWindow { visible: true Column { Button { text: "test" onClicked: Controller.testMethod() } Button { text: "test2" onClicked: Controller.test_method2() } } }With this example, calling
Controller.testMethod()causes the application to crash, whileController.test_method2()works.The only difference between the two methods is that the first uses
@Slot(name="testMethod", result=None)to expose the Python method under a different QML name.Python: 3.14.2
PySide6: 6.11.2
Qt: 6.11.2
OS: Windows 11 -
That produces file:///../Example/Main.qml:11: TypeError: Property 'testMethod' of object Example/Controller is not a function - an instance of Controller is needed.