Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. [SOLVED] How to kill a process/page when the back button is clicked in QML?
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 2 Posters 3.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    honeyhong
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • F Offline
      F Offline
      favoritas37
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • H Offline
        H Offline
        honeyhong
        wrote on last edited by
        #3

        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. :)

        1 Reply Last reply
        0
        • H Offline
          H Offline
          honeyhong
          wrote on last edited by
          #4

          Thanks for the tips :)

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved