Unsolved When qml TableView dynamically creates columns: Expected token `numeric literal' appears
-
import QtQuick 2.15 import QtQuick.Controls 2.12 import Qt.labs.qmlmodels 1.0 import "ui.js" as UI Item { id: root TableModel { id: m // TableModelColumn{display:'a'} // TableModelColumn{display:'b'} rows: [ {"a":1, "b":2}, {"a":3, "b":4}, ] } TableView { width: 300 height: 200 columnSpacing: 0 rowSpacing: 0 clip: true property var columnWidths: [100, 50] property var rowHeights: [50, 20, 10] property alias datas: m.rows model: m columnWidthProvider: function(i) { return columnWidths[i]; } rowHeightProvider: function(i) { return rowHeights[i]; } delegate: Rectangle { implicitWidth: 100 implicitHeight: 50 border.width: 1 Text { text: display anchors.fill: parent wrapMode: Text.WrapAnywhere } } Component.onCompleted: { let qml = "import QtQuick 2.15;import QtQuick.Controls 2.12;import Qt.labs.qmlmodels 1.0;" "TableModelColumn{display:'a'}TableModelColumn{display:'b'}"; Qt.createQmlObject(qml, m, "dytmc"); // console.log("created cols", o); for(let i in datas) { m.appendRow(datas[i]); } } } }
qrc:/qml/com/Table.qml:46: Error: Qt.createQmlObject(): failed to create object: qrc:/qml/com/inline:1:79: Expected token `numeric literal'
-
I'm getting this error in a QML file that contains nothing but import statements.
This appears to be a decade-old bug. It's flagged as an error, but doesn't seem to prevent compilation and running.
-
i have the same problem and i've used Repeater but it gives an error:
Repeater { model: ["name", "color"] delegate: TableModelColumn { display: model } }
the error:
Cannot assign object to list property "columns"