<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[TableView QML problem when I add columns (all cells has the same value)]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">I'm using <strong>Qt 5.5.1</strong> (64 bits) and I have a problem when I try add columns to one QML <strong>TableView</strong>.</p>
<p dir="auto">I wrote a little example with my problem.</p>
<p dir="auto">The program has a TableView and a button to add a new column, and fill the table  with numbers.</p>
<p dir="auto">Columns are added correctly, but when I fill the rows, I always have the same value in all the cells.</p>
<pre><code>import QtQuick 2.3
import QtQuick.Controls 1.2
import QtQuick.Window 2.2

ApplicationWindow {
    title: qsTr("TableView example")
    id: root
    width: 640
    height: 480
    visible: true
    signal addColum();

    onAddColum: {
        var n = table.columnCount
        addColumnToTable("C"+n)
        fillRow()
    }

    function addColumnToTable(name) {
        var columnString = 'import QtQuick 2.3; import QtQuick.Controls 1.2; TableViewColumn {role: "' + name + '"; title: "' + name + '"; }';
        var column = Qt.createQmlObject(columnString, table)
        if (!table.addColumn(column))
            console.log("Error column",name)
    }

    function fillRow() {
        if (!tableModel.count) {
            tableModel.append({"C0":50})
        }
        else {
            tableModel.setProperty(0,"C"+(table.columnCount-1),50+table.columnCount-1)
        }
        var x = tableModel.get(0)
        console.log("Num. Columns",table.columnCount,"row object",JSON.stringify(x))
    }

    ListModel {
        id: tableModel
    }

    TableView  {
        id: table
        anchors.fill: parent
        anchors.margins: 20
        anchors.bottomMargin: 50
        model: tableModel
    }

    Button {
        anchors.top: table.bottom
        anchors.topMargin: 5
        anchors.horizontalCenter: parent.horizontalCenter
        text: "Add"
        onClicked: addColum()
    }
}
</code></pre>
<p dir="auto">This is the console output, that seems OK<br />
qml: Num. Columns 1 row object {"objectName":"","C0":50}<br />
qml: Num. Columns 2 row object {"objectName":"","C0":50,"C1":51}<br />
qml: Num. Columns 3 row object {"objectName":"","C0":50,"C1":51,"C2":52}<br />
qml: Num. Columns 4 row object {"objectName":"","C0":50,"C1":51,"C2":52,"C3":53}</p>
<p dir="auto">And The TableView  is:<br />
C0  C1  C2  C3<br />
50  50  50  50</p>
<p dir="auto">Somebody can found the mistake??</p>
<p dir="auto">thanks</p>
]]></description><link>https://forum.qt.io/topic/64060/tableview-qml-problem-when-i-add-columns-all-cells-has-the-same-value</link><generator>RSS for Node</generator><lastBuildDate>Sat, 13 Jun 2026 05:40:20 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/64060.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 11 Feb 2016 06:17:00 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to TableView QML problem when I add columns (all cells has the same value) on Wed, 24 Feb 2016 06:30:12 GMT]]></title><description><![CDATA[<p dir="auto">Finally I solved it!!!</p>
<pre><code>    function fillRow() {
        table.model = undefined  // &lt;--- 1
        if (!tableModel.count) {
            tableModel.append({"C0":50})
        }
        else {
            tableModel.setProperty(0,"C"+(table.columnCount-1),50+table.columnCount-1)
        }
        table.model = tableModel    //&lt;--- 2

        var x = tableModel.get(0)
        console.log("Num. Columns",table.columnCount,"row object",JSON.stringify(x))
    }
</code></pre>
<p dir="auto">When I fill the columns, I set TableView.model to undefined(1), then fill the rows, and after I set TableView.model to ListModel again(2)</p>
]]></description><link>https://forum.qt.io/post/314991</link><guid isPermaLink="true">https://forum.qt.io/post/314991</guid><dc:creator><![CDATA[roigallego]]></dc:creator><pubDate>Wed, 24 Feb 2016 06:30:12 GMT</pubDate></item></channel></rss>