1

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

import QtQuick
import QtQuick.Controls
import QtQuick.Layouts

Page {
    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.text2
text: text2

Can anyone see obvious problem with this?

2
  • 2
    Try adding required property string text2 to Item, and use text: parent.text2. Commented Jan 10 at 15:13
  • 1
    Thanks! It works :), just need add some height to Item, in other case, all strings will appear in the same place Commented Jan 10 at 15:24

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.