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. Properly destroying qml objects
Forum Updated to NodeBB v4.3 + New Features

Properly destroying qml objects

Scheduled Pinned Locked Moved QML and Qt Quick
1 Posts 1 Posters 644 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.
  • X Offline
    X Offline
    xcoder
    wrote on 17 Sept 2014, 10:05 last edited by
    #1

    Hello again,

    I'm a bit confused again with QML. I have a situation where I dynamically add objects to a row. When a new file is opened the row should be cleared from the dynamic objects.

    As of now I'm doing it like this, where layerRow is obviously and ID for Row item:

    @function clear() {
    for(var i=0; i<layerRow.children.length; i++)
    layerRow.children[i].destroy()
    }@

    From C++ I invoke the function the following way:
    @
    QMetaObject::invokeMethod(layerPanel, "clear");
    @

    It kinda works, it clears the scene, but it doesn't happen immediately. Basically, for every object added to the Row I set objectName property to be L0, L1, L2 etc. So I'm able to find them and populate them from C++. The problem is when clear function is invoked, the C++ continues to execute the rest of the code before they are removed and doesn't find the new object properly, it finds the old and the new object.

    It does work, when the Row initially is clear, then in C++ I find only one object by name:
    @
    (Layer_QMLTYPE_19(0x23791ce8, name = "L0") )
    @

    And here is when I tried to clear and readd the items to the Row:
    @
    (Layer_QMLTYPE_19(0x23791ce8, name = "L0") , Layer_QMLTYPE_19(0x2ccb83e0, name = "L0") )
    @

    As you can see by the object address, it found the previous object, even though clear was invoked before.

    If I wait a bit, it will eventually return the children correctly.

    I kinda could avoid the problem by saving the addresses of previous objects and then finding the new object by checking that it didn't exist before. Or maybe I could connect destroyed signal and count if all of them were destroyed before continuing. I'm not particulary pleased with my ideas, hence, the question, is there a proper/better way of destroying items?

    Thanks.

    Only a biker knows why a dog sticks his head out of a car window.

    1 Reply Last reply
    0

    1/1

    17 Sept 2014, 10:05

    • Login

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