onDestruction is never called in the QML component

Bug #1477363 reported by XiaoGuo, Liu
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
ubuntu-ui-toolkit (Ubuntu)
Invalid
Undecided
Unassigned

Bug Description

I have created a very simple application, and I want to capture the onDestruction event. However, it is never called on a phone, but it is called on the desktop. On the page, http://developer.ubuntu.com/api/apps/qml/sdk-15.04/Qt.labs.settings.Settings/, it is used to save the state of the application.

  Page {
        title: i18n.tr("ondestruction")

        Column {
            spacing: units.gu(1)
            anchors {
                margins: units.gu(2)
                fill: parent
            }

            Label {
                id: label
                objectName: "label"

                text: i18n.tr("Hello..")
            }

            Button {
                objectName: "button"
                width: parent.width

                text: i18n.tr("Tap me!")

                onClicked: {
                    label.text = i18n.tr("..world!")
                }
            }
        }

        Component.onDestruction: {
            console.log("ondestruction")
        }
    }

Revision history for this message
Zsombor Egri (zsombi) wrote :

Could you be more specific? Like in what context the Page is used? Is it declared inside a PageStack? or in a separate document? Are you trying to use it in a PageStack?

Changed in ubuntu-ui-toolkit (Ubuntu):
status: New → Incomplete
Revision history for this message
XiaoGuo, Liu (liu-xiao-guo) wrote :

Can you take a look at the code I showed above? it is in the mainview. Please find the code at:

bzr branch lp:~liu-xiao-guo/debiantrial/ondestruction

On the setting page, it is used as an example for saving the state. If I understand correctly, it should be called like "Component.onCompleted" event for each of the component.

Thanks & best regards,
XiaoGuo

Revision history for this message
Launchpad Janitor (janitor) wrote :

[Expired for ubuntu-ui-toolkit (Ubuntu) because there has been no activity for 60 days.]

Changed in ubuntu-ui-toolkit (Ubuntu):
status: Incomplete → Expired
Revision history for this message
XiaoGuo, Liu (liu-xiao-guo) wrote :

This needs to be fixed

Changed in ubuntu-ui-toolkit (Ubuntu):
status: Expired → New
Revision history for this message
Zsombor Egri (zsombi) wrote :

In your example, the Page is declared as an instance. When you close the application, the elements will be destroyed silently, without having their attached Component.onDestruction called.

When you use a Page declared in the way you reported in a PageStack or AdaptivePageLayout, the Page will not be destroyed by these components as it has not been created by the PageStack/AdaptivePagelayout. So you won't get the onDestruction triggered either. In order to have that coming, you need to declare your page as component and add that to the PageStack/AdaptivePageLayout, or in a separate QML document and use that.

Changed in ubuntu-ui-toolkit (Ubuntu):
status: New → Invalid
Revision history for this message
XiaoGuo, Liu (liu-xiao-guo) wrote :

But the same code on desktop has the output.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.