Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Instantiator Active Bug



  • If active is false, and I modify the ListModel dynamically, then the Instantiator will create "some" objects. I have found if there were ListElements defined first, then each insert into the ListModel would cause the Instantiator to create those first. Either way, it shouldn't be creating anything.

    I was trying to reproduce the code where the bug started. That is why there is a StackView and Page. Probably not related to the issue.

    import QtQuick 2.12
    import QtQuick.Window 2.12
    import QtQuick.Controls 2.15
    import QtQml.Models 2.15
    
    Window {
        visible: true
        width: 640
        height: 480
        title: qsTr("Instantiator Active Bug")
    
        ListModel {
            id: listmodel
    
            dynamicRoles: true
    
            /*
            ListElement{name:"not one"}
            ListElement{name:"not two"}
            ListElement{name:"not three"}
            */
        }
    
        Component.onCompleted: {
            if(1){
                listmodel.insert(listmodel.count, {name: "one"})
                listmodel.insert(listmodel.count, {name: "two"})
                listmodel.insert(listmodel.count, {name: "three"})
            }
        }
    
        StackView {
            anchors.fill: parent
    
            initialItem: page1
        }
    
        Component {
            id: page1
    
            Page {
                Instantiator {
                    id: instantiator
    
                    // https://doc.qt.io/qt-5/qml-qtqml-models-instantiator.html#active-prop
                    active: false
    
                    model: listmodel
    
                    delegate: Text {
                        width: 100
                        height: 20
    
                        text: name
    
                        Component.onCompleted: console.log(instantiator.active, name)
                    }
    
                    onObjectAdded: column.data.push(object)
    
                    onActiveChanged: console.log(active)
                }
    
                Column {
                    id: column
                }
            }
        }
    }
    

    I think I have to figure out how to use just one Instantiator in my code. I will submit a bug report, but people might be interested in this so I am posting here. I tried multiple versions of import QtQml.Models and it didn't have an effect.




Log in to reply