Search code examples
qtqmlqt3d

Unable to assign Qt3DCore::Quick::Quick3DEntity to QQmlComponent


Trying to add a delegate-like property to a custom Qt3D entity:

MyEntity.qml:

Entity {
    id: root
    default property Entity delegate // <-- MyEntity.qml:26
    property int n: 1
    property matrix4x4 t

    NodeInstantiator {
        id: rep
        model: root.n
        delegate: Entity {
            components: [
                Transform {
                    matrix: {
                        var m = root.t
                        for(var i = 1; i < rep.index; i++)
                            m = m.times(root.t)
                        return m
                    }
                }
            ]
            NodeInstantiator {
                delegate: root.delegate
            }
        }
    }
}

Usage:

MyEntity {
    t: Qt.matrix4x4(
           1, 0, 0, 0.1,
           0, 1, 0, 0,
           0, 0, 1, 0,
           0, 0, 0, 1
    )
    n: 5
    Entity {...}
}

Result:

qrc:/MyEntity.qml:26:17: Unable to assign Qt3DCore::Quick::Quick3DEntity to QQmlComponent


Solution

  • The property declaration:

    default property Entity delegate
    

    must be changed to:

    default property Component delegate
    

    to work properly.