Important: Please read the Qt Code of Conduct -

Object id visibility in QML

  • If A.qml is a composition in B.qml which is a composition in main.qml then A.qml can see and refer to all object id's in B.qml as well as main.qml. Is doing so recommended as a good practice in qml world ?

    Rectangle {
    //can see and use objRoot - see main.qml below

    Item {
    One {
    id: one

    A {


    Rectangle {
    id: objRoot

    B {


    An eg. when this could be required: A.qml has a drag-able component. Then when it is dragged we would need to call ParentChange to make objRoot the parent for the duration of the drag so that it remains a top level item, visible no matter where it's dragged around the window.

    If this is not a good practice then what's the alternative ?

Log in to reply