Search code examples
qtqmlqt3d

How Access components inside NodeInstantiator Delegate?


I have a line class in C++ and I want to use it in qml. I want to draw a line by mouse and have multiple lines. In fact, I want to new my line class, so I use NodeInstantiator.

 ListModel {
    id: entityModel

   }
 NodeInstantiator {
    id: instance

    model: entityModel

    delegate: Entity {
        id: sphereEntity

        components: [
            Line { id:lineMesh } ,

            PhongMaterial { id: material; ambient:"red" },

            Transform { id: transform;  }
        ]
    }
}

My problem is that I can't use Line Component with its id lineMesh outside NodeInstantiator, and also I don't know how to generate lines and add them to its entityModel.

If I don't use NodeInstantiator , when I draw lines by left button of mouse and then use Right Button drawing stops. then in the second time , when I use left button I want New Line Entity .

enter image description here

As picture shows now I can draw line just one time .


Solution

  • I Fixed My problem in CPP , which means that I create a class that plays a wrapper role in my program and It is responsible for collecting points . I new my line class here .

    There is a bug in Qt3D NodeInstantiator: It will crash when used with ObjectModel. Thus, there is an explicit ListModel at the moment.