Catching close events in QML or C++
-
Is there a way to get a signal when the user closes an app? (not backgrounding, but complete app close)
Doesn't matter if its via QML or C++, both would be fine for me. -
Humm lets try the obvious child, how about the destructor of QApplication? See https://stackoverflow.com/questions/4381841/qt-how-to-intercept-the-applications-close-event-if-theres-one

-
@flohack And in the destructor of the QApplication, will the QML engine and all the stuff still exist and work?
[edit] Maybe I should have mentioned that, while C++ is an option, I need to trigger actions in QML, namely stopping
MediaPlayerplayback. -
Oh well

Maybe better then to hook https://doc.qt.io/qt-5/qquickwindow.html#closing ? Or similar, Google will help you out. -
@flohack Yeah well, as I said, I don't have a window. I have a
QQuickViewor aUbuntu.Components MainView.
I have already googled quite a bit and tried several solutions, but none worked, thats why I ask here. -
@s710 Well they should be derived and as such have that event too. Did you try out to subscribe ?
-
@flohack Yep.
qrc:/Main.qml:20:4: Cannot assign to non-existent property "onClosing" -
Maybe play with applicationState : see https://stackoverflow.com/questions/50845884/how-to-listen-to-qguiapplicationapplicationstatechanged-signals-directly-in-a
-
@lduboeuf This works, but it does not provide any info about the app closing. Only active/inactive/hidden/suspended.
-
Got it, after googling even more. Some guy at the QT forum revealed:
Connections { target: Qt.application onAboutToQuit: { audioPlayer.stop() }This works

Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better π
Register Login