qttableviewqmlqtquick2

Get TableView cell content


I would like to read specific data from a database, visualise the data in a table and write everything to another database.

But, I have some problems with reading the table. How do I get access to specific table cells?

import QtQuick 2.4
import QtQuick.Window 2.2
import QtQuick.Controls 1.3

ApplicationWindow {
    id: mainwindow
    width: 400
    height: 400
    visible: true

    Column {
        Button {
            id: printbutton
            width: mainwindow.width
            height: 30
            text: "Print"
            //Print TableView Cell
            onClicked: console.log("tableview.row[1].column[1]")
        }

        ListModel {
            id: libraryModel
            ListElement{ title: "A Masterpiece" ; author: "Gabriel" }
            ListElement{ title: "Brilliance"    ; author: "Jens" }
            ListElement{ title: "Outstanding"   ; author: "Frederik" }
        }

        TableView {
            width: mainwindow.width
            height: mainwindow.height - printbutton.height
            TableViewColumn{ role: "title"  ; title: "Title" ; width: 100 }
            TableViewColumn{ role: "author" ; title: "Author" ; width: 200 }
            model: libraryModel
        }
    }
}

Solution

  • If you want to access the model data you can use functions that you can find in documentation. Have a look at get for model that you use in QML or data for C++ models.