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. Dynamic lifecycle of Qt Quick objects
Forum Update on Monday, May 27th 2025

Dynamic lifecycle of Qt Quick objects

Scheduled Pinned Locked Moved QML and Qt Quick
6 Posts 3 Posters 3.1k Views
  • 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
    hamishwillee
    wrote on 30 Nov 2011, 07:02 last edited by
    #1

    Hi
    I understand that you can permanently create a QML object as a sub-element by describing it inside another object, or by describing it in a qml file and creating it as a property of the parent object.

    You can also dynamically create objects from a file or from a string in javascript as described here: http://doc.qt.nokia.com/latest/qdeclarativedynamicobjects.html

    There is one more way to create a dynamic object - you can do the following:
    @pageStack.push(Qt.resolvedUrl("pages/HomePage.qml")@

    My question is this, if you declare a page using Qt.resolvedUrl, what is its lifetime/who is its owner? Can it be deleted - for example if you pop it off the pagestack is it automatically deleted?

    1 Reply Last reply
    0
    • T Offline
      T Offline
      task_struct
      wrote on 30 Nov 2011, 07:35 last edited by
      #2

      Hi,

      I think the owner of new pages is PageStack that create them. A page is destroyed when it is not longer needed( i.e. it is removed from stack by pop(), remove() or clear() )

      "Most good programmers do programming not because they expect to get paid or get adulation by the public, but because it is fun to program."

      • Linu...
      1 Reply Last reply
      0
      • H Offline
        H Offline
        hamishwillee
        wrote on 30 Nov 2011, 09:32 last edited by
        #3

        Thanks. But the implication is that if you call the push multiple times over the life of your app you'll get multiple instances - ie a memory leak. Is there a way to destroy an object created in this way? ie what happens if you pop the instance? Who owns it then?

        1 Reply Last reply
        0
        • H Offline
          H Offline
          hamishwillee
          wrote on 30 Nov 2011, 09:58 last edited by
          #4

          Experimentation shows that when you pop the page it is destroyed, as you would hope.

          1 Reply Last reply
          0
          • T Offline
            T Offline
            task_struct
            wrote on 30 Nov 2011, 11:45 last edited by
            #5

            The concept of interface is based on stack. When you start an app you got only a start page. When you enter subpage it is pushed in stack and when you go back it is poped from stack and memory is released. And when you enter in subpage again, new instance is created( old one has been removed by pop() ). So most of time you'll got only a few pages in stack.

            "Most good programmers do programming not because they expect to get paid or get adulation by the public, but because it is fun to program."

            • Linu...
            1 Reply Last reply
            0
            • S Offline
              S Offline
              SteveKing
              wrote on 30 Nov 2011, 11:56 last edited by
              #6

              One thing to watch with this is that there is a wrapping component around the page, and this doesn't seem to be destroyed. You will get one of these for each (unique?) page that has been pushed onto the stack.

              1 Reply Last reply
              0

              1/6

              30 Nov 2011, 07:02

              • Login

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