Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. When qml TableView dynamically creates columns: Expected token `numeric literal' appears
Forum Updated to NodeBB v4.3 + New Features

When qml TableView dynamically creates columns: Expected token `numeric literal' appears

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
3 Posts 3 Posters 586 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    senmx
    wrote on last edited by
    #1
    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'
    
    1 Reply Last reply
    0
    • StokestackS Offline
      StokestackS Offline
      Stokestack
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • Q Offline
        Q Offline
        qAminzzz
        wrote on last edited by
        #3

        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"

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved