QML Window onClose event not working in some cases



  • I am still new to qt/qml and having some issues with having my application stop on shutdown. This is to allow the user to save his work before he closes the app. At the moment I only see this on OS X, as its the only OS that creates a default menu item called (MyAppName). I am able to reproduce this issue with Qt 5.3 and Qt 5.4. There are a couple similar bugs listed in QTBUGS "#40093":https://bugreports.qt.io/browse/QTBUG-40093 but no one seems to have any work arounds or suggestions. I also see the same issue here with my onClosing not being recognized "#13347":https://bugreports.qt.io/browse/QTCREATORBUG-13347, which maybe related.

    Code:
    @
    import QtQuick 2.0
    import QtQuick.Window 2.2
    import QtGraphicalEffects 1.0

    Window {
    id: splashWindow
    objectName: "splashWindow"

    visible: true
    width: ( (Qt.platform.os == "ios" ) || (Qt.platform.os == "android") ) ? Screen.width : 1366
    height: ( (Qt.platform.os == "ios" ) || (Qt.platform.os == "android") ) ? Screen.height : 768
    
    Loader {
           id: myLoader
           width: parent.width
           height: parent.height
        }
    
    Timer{
        id: loadingTimer
        interval: 1000
        running: false
        repeat: false
        onRunningChanged: {
            if(!loadingTimer.running){
                myLoader.source = "main.qml";
                mainContainer.visible = false;
            }
        }
    }
    
    Rectangle{
        id: mainContainer
        width: parent.width
        height: parent.height
        color: "transparent"
        state: "loading"
    
        Image{
            id: mainBackground
            source: "/svgs/headerbgparallax.png"
            width: parent.width
            height: parent.height
        }
    
        Image{
            id: mainLogo
            source: "/svgs/logo.svg"
            width: 328
            height: 159
            anchors.centerIn: parent
    
            MouseArea{
                id: ma
                anchors.fill: mainLogo
                onClicked: {
                    myLoader.source = "main.qml";
                    mainContainer.visible = false;
                }
            }
        }
    
        ZoomBlur {
            id: zb
            width: mainLogo.width
            height: mainLogo.height
            anchors.centerIn: mainLogo
            source: mainLogo
            samples: 24
            length: 0
            visible: false
        }
    }
    
    Component.onCompleted: {
        loadingTimer.start();
    }
    
    onClosing: {
        close.accepted = false;
        myLoader.item.saveOnShutdown();
    }
    

    }
    @

    onClosing

    @close.accepted = false;@

    works for users when they click the red X(window close), but if they go to the (MyAppName)->quit menu item it does not seem to handle the change to accepted. I even see the dialog show up but the app closes before the user can do anything. I do not create or alter any menu items for the application. If I am doing anything incorrectly glad to learn the right way and also any ideas for work arounds to this issue. Thanks!


  • Moderators

    Hi,

    It definitely seems to be a bug. See "QTBUG-35390":https://bugreports.qt.io/browse/QTBUG-35390. There's a workaround mentioned in the last comment there.


Log in to reply
 

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