Adding ListModel data to a model
Unsolved
QML and Qt Quick
-
Hi,
I am trying to add ListModel items to a model used to populate a SimpleSection and a repeater:import Felgo 3.0
import QtQuick 2.9
import QtQuick.Controls 2.5
import QtQuick.Controls.Styles 1.4
import QtQuick.LocalStorage 2.12
import "Database.js" as JSApp {
AppListView { id: myListView ListModel { id: listModel } model: { var model = [] for (var i = 0; i < 26; i++) { for (var j = 0; j <= listModel.count; j++) { var entry = { "section": String.fromCharCode((65 + i)), "items": [{ "text": listModel.wordField }] } } model.push(entry) } return model } // add sections as regular list items delegate: Item { width: parent.width height: contentCol.height // each list-entry holds the section header + section items Column { id: contentCol width: parent.width // header SimpleSection { // manually set otherwise induced section title property string section: modelData.section width: parent.width enabled: true // clickable sections onSelected: { sectionItems.visible = !sectionItems.visible } } // items Column { id: sectionItems width: parent.width visible: false //show all items of section with repeater Repeater { model: modelData.items delegate: SimpleRow { text: modelData.text } } } } } }
}
When I replace the "listModel.wordField" in the model for a string like "car" it works. I assume the problem is that I incorrectly assign string to "text" which causes the "Unable to assign [undefined] to QString" error message. Please help me to figure out the right way of doing this.
Thank you for your help. -
Have a look at these documents:
https://doc.qt.io/qt-5/qml-string.html
https://doc.qt.io/qt-5/qml-qtqml-string.htmlI believe you need a string, not a String.