Repeater on SelectionDialog



  • Hi I'm trying to insert ListElements using a repeater but it doesn't work, I have not seen an exmple of something like this being made, the code is:

    @
    SelectionDialog {
    id: singleSelectionDialog
    titleText: "Indice"
    selectedIndex: 1

            model: ListModel {
                Repeater {
                         model: 100
                         ListElement { name: "> " + index }
                     }
            }
        }
    

    @

    The error I get is:

    @
    "ListElement: cannot contain nested elements"
    @

    I think I'm missing something about models, so if there's something I can read that helps me get that working, please tell me, thanks!



  • A Repeater is a view-type element, like a ListView or a GridView, that is used to create multiple copies of visual items, not non-visual items like the ListElements in a ListModel.

    For your case, you could try populating the model using JavaScript, e.g. when the model is loaded, like this:

    @
    model: ListModel {
    id: model

    Component.onCompleted: {
        for (var i=0; i<100; i++)
            model.append({"name": "> " + i})
    }
    

    }
    @



  • Thank you so much, that's exactly what I needed!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.