Hello,
I’m trying to insert the values from a Database (SQLite) into a MenuItem (so with a repeater). The database consists of two tables with text data. As such: xx|XXXX. The end goal being to retrieve all lines from the DB and make a MenuItem of each line. I think the Repeater is the optimal solution.
As you can see in the code bellow, I have a function “get()” that actually gets the data from the DB. And then I call that function from within the Repeater, so it can be used for the Model.
That’s where it doesn’t workout for me, no data gets to the Repeater part (or the Model), even when using a global function. I don’t think (and i tried), putting the function inside the Repeater would be the correct option either.
ComboBox {
id: comboBox
label: “List”function getDatabase() { return LocalStorage.openDatabaseSync("MyDatabase", "1", "My DataBase", 100000); } function get() { var db = getDatabase(); db.transaction(function(tx) { var rs = tx.executeSql('SELECT * FROM Table1'); var r = ""; for (var i = 0; i < rs.rows.length; i++) { r += rs.rows.item(i).table1_value + "\n" } return r; } ); } menu : ContextMenu { id: contextMenu Repeater { id: repeaterLang Component.onCompleted: comboBox.get() model: comboBox.get() MenuItem { id: menuItem text: "%1".arg(modelData) } } } }
Do you have any suggestion or code examples ?
Thank you !