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

Too often called createObject



  • Rectangle {
        id: rect1
        color: Material.backgroundColor
        ....
        ListView {
            id: listView
            model: myModel
    
            delegate: Rectangle {
                Row {
                    ...
                        Component {
                            id: componentText
                            Text {
                                id: nameLink
                                text: qsTr("Hello World!")
                            }
    
                        }
                        Column {
                            id: column
                            resources:
                            {
                                        for(var i=0; i<modelPath.length; i++) {
                                            var path = modelPath[i]
                                            componentText.createObject(column, {"text": "path name: '" + path })
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    

    If I run the code the first time column has the same number of items as the number of modelPath.length. After a switch was pressed the color changed. Hence the above code is running again and after that my column component has twice as many number of items as the number of modelPath.length.
    The information of the switch comes from another .qml-file.
    Is it possible that the column component are create once?


  • Qt Champions 2018

    Don't use createObject.

    Column {
        Repeater {
            model: modelPath
            Text {
                text: "path name: " + modelData
            }
        }
    }
    


  • With Repeater I got a column with modelPath entries and each entry has all my paths. I want a column with each line has one path



  • You can also nest ListViews if that is easier. What does you modelPath data look like?


  • Qt Champions 2018

    @KaNe09 said in Too often called createObject:

    With Repeater I got a column with modelPath entries and each entry has all my paths. I want a column with each line has one path

    That's what the code I pasted does, equivalent to what your imperative code did.
    It creates a Text for each path of your modelPath



  • This post is deleted!

Log in to reply