Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

on ubuntu touch. I run an application in terminal and close the application in the Application scope. The application isn't killed. And no event is caught in QQuickView.

How do I detect this close event?

share|improve this question
Today I tried it on the new image. It is killed using SIGTERM in Application scope now. I guess it is fixed now. Now I can just catch signal SIGTERM and do a grace clean up. – Boren Zhang Apr 23 '14 at 22:33
Don't know how to do it in QML though – Boren Zhang Apr 23 '14 at 22:34
Did you test my answer with the new 14.04 image? – Sylvain Pineau Apr 24 '14 at 11:00

The close event in QML seems to be a recent addition (Qt 5.1) so only 14.04 which provides Qt 5.2 will be able to catch such event with this kind of handler:

import QtQuick 2.1
import QtQuick.Window 2.1

Window {
    onClosing: {

Alternatively you can also use onVisibleChanged signal handler.


share|improve this answer
Thank you for the answer. I tried this on Ubuntu touch. There is no Window available. There is no onClosing for MainView. I am not sure whether I have installed the correct package. – Boren Zhang Apr 23 '14 at 22:30
You should test this code on a daily image to ensure that you have Qt5.2. Where did you get your current image? – Sylvain Pineau Apr 23 '14 at 22:35
phablet@ubuntu-phablet:~/tmp$ qmlscene main.qml <br> --desktop_file_hint=/home/phable phable/ phablet/ phablet@ubuntu-phablet:~/tmp$ qmlscene main.qml --desktop_file_hint=/home/phablet/.local/share/click/hooks/desktop/com.ubuntu.te‌​‌​rminal_terminal_0.5.53.desktop <br> callbacks 0xb3d925f9 0xb3d925a5 <br> creating surface at (0, 58) with size (768, 1222) with title 'Window 1'Terminated <br> phablet@ubuntu-phablet:~/tmp$ cat main.qml <br> import QtQuick 2.1 <br> import QtQuick.Window 2.1 <br> Window { <br> onClosing: { <br> console.log("Bye") <br> } <br> } – Boren Zhang Apr 28 '14 at 6:18
I have verified that I am using qt 5.2.1. I tried your example. Run it and close the application in the application scope. I still cannot see the "Bye" in the output. I think the application is simply get killed. – Boren Zhang Apr 28 '14 at 6:20

This should do the job:

MainView {
    id: myApp
    objectName: "myApp"
    Component.onDestruction: {
        console.log('~~~~~~~~~~~ bye!!! ~~~~~~~~~');

Best regards!

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.