Qml application closing issue

77 Views Asked by At

I'm building one qml application and I printing console log's every where but if I minimize application and try to close from taskbar how will I capture that close event in console log. I'm using QT 5.13 version.

Component.onCompleted: {
       Qt.application.activeChanged.connect(function() {
           if (!Qt.application.active) {
               console.log("Application closed from taskbar")
           }
       })
   }

I tried this above code but this code is printing console log based on visibility if i minimize the application then it's printing which is wrong

1

There are 1 best solutions below

4
Öö Tiib On

Application should emit aboutToQuit signal when it is about to quit.

To QML it is exposed as Application singleton that you can use like:

    import QtQuick

    Window {
        id: root
        visible: true
        width: 800
        height: 680
    
        title: `${Application.name} (${Application.version})`
    
        Connections {
            target: Application
            function onAboutToQuit() {
                console.log("Bye!")
            }
        }
    }