Quantcast
Channel: Active questions tagged listview - Stack Overflow
Viewing all articles
Browse latest Browse all 611

Problem with usage ListModel in ListView in QML

$
0
0

Got problem with ListView using ListModel. Code seems to be straightforward and quite simple, but I missed something and cannot figure it out:

import QtQuickimport QtQuick.Controlsimport QtQuick.LayoutsPage {    ListModel {        id: listModelA        ListElement { text2: "aaa" }        ListElement { text2: "bbb" }        ListElement { text2: "ccc" }        ListElement { text2: "ddd" }    }    ...    Component {        id: comp2            Column {            ListView {                id: listA                width: parent.width                height: 100                model: listModelA                delegate:                Item {                    id: aaa                     Text {                        width: 100                        height: 20                        text: text2  // problematic line                        }                    }            }        }    }}

Seems that "text2" field from model data cannot be resolved. QtCreator gives me warning Unqalified access: Did you mean "text"? After running application, got runtime error in console: ReferenceError: text2 is not defined. Tried different solution, e.g, but nothing works:

// text: listA.model.text2// text: listModelA.text2// text: model.text2text: text2

Can anyone see obvious problem with this?


Viewing all articles
Browse latest Browse all 611

Trending Articles