Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Pyside6 Slot with Name arg crashes app
Qt 6.11 is out! See what's new in the release blog

Pyside6 Slot with Name arg crashes app

Scheduled Pinned Locked Moved Unsolved Qt for Python
4 Posts 2 Posters 301 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Leooooooooo
    wrote last edited by
    #1

    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
    }
    
    1 Reply Last reply
    0
    • F Offline
      F Offline
      friedemannkleint
      wrote last edited by
      #2

      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 )?

      L 1 Reply Last reply
      0
      • F friedemannkleint

        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 )?

        L Offline
        L Offline
        Leooooooooo
        wrote last edited by
        #3

        @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, while Controller.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

        1 Reply Last reply
        0
        • F Offline
          F Offline
          friedemannkleint
          wrote last edited by
          #4

          That produces file:///../Example/Main.qml:11: TypeError: Property 'testMethod' of object Example/Controller is not a function - an instance of Controller is needed.

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved