Search code examples
qtqmlqt5listmodel

How do you iterate through all elements of a QML ListModel?


How can you iterate through all the individual ListElement(s) of a ListModel in QML?


Solution

  • I was surprised how hard it was to find an answer to this question myself. Since I could not find a related question already on SO, I'm answering it myself here.

    for( var i = 0; i < listModelID.rowCount(); i++ ) {
        console.log( listModelID.get(i).<yourPropertyName> );
    }