2
votes

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
        }
    }
}
1
It's not really clear what you're asking here. Is the database in the QML layer or C++? What exactly are you trying to print in that console log?MrEricSir
The database ist in the QML laye and the console log ist just an example. I need something like 'table.row[a].column[b]'.SLx64
You wouldn't get the data from the view, you get it from the model - so post the code for that.cmannett85
If you're just using a QML ListModel to store the data, its API is documented here: doc.qt.io/qt-5/qml-qtqml-models-listmodel.htmlMrEricSir
As was said above, TableView just displays data,provided by model. So all you need is just to query model, for example: model.getRow(index).authorfolibis

1 Answers

1
votes

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.