Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QQuickCloseEvent Undefined Type?



  • I am doing some refactoring of my QML and Python source to eliminate redundancy and condense the code base, and I noticed that this seemly innocuous change does not work.

    The original QML files for Window components (Qt Quick 2 widgets) would register signal handlers for the closing signal as follows:
    onClosing: handler_fn()

    Rather than have every Window need to declare this handler, I tried to connect to this signal in Python using window.closing.connect(callback), however that doesn't seem to work. I see the following error in the logs: TypeError: Can't call meta function because I have no idea how to handle QQuickCloseEvent*

    Looking at the Qt source, it seems that the QQuickCloseEvent type is undefined in PySide2, even though it isn't listed in the list of missing bindings.

    Am I missing something here? How can I connect to this signal in Python?

    Here's a test script to reproduce the issue:

    from PySide2.QtWidgets import QApplication
    from PySide2.QtQuick import QQuickWindow
    
    def on_close(_):
        print('Closing window')
    
    def mk_app():
        app = QApplication()
        app.setQuitOnLastWindowClosed(True)
        wnd = QQuickWindow()
        wnd.closing.connect(on_close)
        wnd.show()
        app.exec_()
    
    if __name__ == '__main__':
        mk_app()
    


  • I actually figured out a method. Turns out QQuickCloseEvent is a private type, so this was never going to work.

    My solution is to simply use a event handler in the qml itself:

    Window {
        onClosing: do_stuff()
        ...
    }
    

Log in to reply