Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. QML Window onClose event not working in some cases
Qt 6.11 is out! See what's new in the release blog

QML Window onClose event not working in some cases

Scheduled Pinned Locked Moved QML and Qt Quick
2 Posts 2 Posters 8.0k 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.
  • D Offline
    D Offline
    drakebp
    wrote on last edited by
    #1

    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!

    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      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.

      157

      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