[SOLVED] How to kill a process/page when the back button is clicked in QML?



  • I have this function for my back button. I used this for every page.
    @
    ToolButton
    {
    id:buttonMenu
    iconSource:"toolbar-view-menu"
    anchors{top:header.bottom; left:parent.left; leftMargin:5;}
    onClicked: window.pageStack.depth <= 1 ? Qt.quit() : window.pageStack.pop()
    }
    @

    The application took up a lot of memory in the phone. I want to kill/end the process of the current page when i click the back/menu button to navigate to the previous page/other page. Is there such function? If there is, can someone tell me how?



  • The application runs in only one process regardless the pages you have pushed to the PageStack. So don't get confused on this one.

    The memory management is differentiated only by the way you push the new pages to the PageStack.

    For example, if the "page you are going to push is already declared":http://doc.qt.nokia.com/qt-components-symbian/qml-pagestack.html#pushing-a-qml-item-page then regardless the page stack operations it will remain in memory:
    @
    Window{
    Page{
    id: page1
    }

    PageStack{
    id:pagestack
    }

    Component.onCompleted: pagestack.push(page1)
    }
    @

    But if you go with the dynamic object creation (from "here":http://doc.qt.nokia.com/qt-components-symbian/qml-pagestack.html#pushing-a-qml-component-page-defined-in-a-component-file and "here":http://doc.qt.nokia.com/qt-components-symbian/qml-pagestack.html#pushing-a-qml-component-page) any page you push gets created at the time of the push and gets destroyed when popped. This means that the page allocated will be destroyed if popped. This is what you want.

    MyComponent.qml
    @
    Page{
    //here you create your page
    }
    @

    MainPage.qml
    @
    Window{
    PageStack{
    id:pagestack
    }

    Component.onCompleted: pagestack.push(Qt.resolvedUrl("MyComponent.qml"))
    }
    @

    So take a look at the above links and if you have any questions feel free to ask.



  • Hey favoritas37,

    Thank you so much for the clear explanation. I finally understood the difference of using declared page and dynamic object creation.

    Now I changed all that are necessary to Qt.resolvedUrl.
    @ onClicked: container.pageStack.push(Qt.resolvedUrl("../HomePage.qml")) @

    Will test it out in the phone when I get my hands on it. Should not crash as much now. :)

    However, for those pages that are linked by using id from XmlListModel, I could not use Qt.resolvedUrl because when the page is reloaded, it would not be able to detect from which id the data was earlier derived from. In this case, declaring the page would be the option.
    @ onClicked: window.pageStack.depth <= 1 ? Qt.quit() : window.pageStack.pop() @

    Thank you very much for your help. Got my problem solved now. :)



  • Thanks for the tips :)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.