".onClosing" is not available due to component versioning



  • I write a simple program look at this:

    import QtQuick 2.10
    import QtQuick.Window 2.10
    
    Window {
        visible: true
        width: 640
        height: 480
        title: qsTr("Hello World")
    
        Item
        {
            //property Window theWindow: Window.window
            Window.window.onClosing:
            {
                console.warn( "我们就是要清除了哦。" );
            }
        }
    }
    

    But unfortunately it turns out:

    qrc:/main.qml:13 ".onClosing" is not available due to component versioning.

    How can I resolve the problem? Thanks in advance.


  • Moderators

    @jiancaiyang said in ".onClosing" is not available due to component versioning:

    Window.window.onClosing:

    The attached property of "Window" is called "window", so that line should read:

    window.onClosing: {
      // ...
    }
    

    But better handle the signal in the window itself, not in it's child component.



  • In fact, some other component could be able to handle window's closing event even if out-of-scope. So I am trying to read Window's instance in that way. Finally I found this way worked:

    import QtQuick 2.10
    import QtQuick.Window 2.10
    
    Window {
        visible: true
        width: 640
        height: 480
        title: qsTr("Hello World")
    
        Item
        {
            id: root
            property Window theWindow: Window.window
            Connections
            {
                target: root.theWindow
                onClosing:
                {
                    console.log( "我们就是要清除了哦。" );
                }
            }
        }
    }
    

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.