QML: Get QObject parent



  • QML introduces a separate ownership (QObject) tree from the visual tree (QtQuick scene graph).

    • parent returns the visual parent.
    • children returns the visual children.
    • data returns the QObject children.
    • But how do I access the QObject parent?

    FYI, I intend on dynamically creating and destroying nested layouts containing a custom type, so I need to manage the QObject tree - just using the visual tree will result in the 'wrong' objects disappearing after reparenting and later deleting.


  • Moderators

    Very easy to do on the C++ side, just pass your item there and it's easily castable to QObject.

    Or try with parent.data, although your post would suggest it can return false data.


Log in to reply