Important: Please read the Qt Code of Conduct -

How do I populate the table with the sql data

  • Re: How do I retrieve locally stored sql file and parse it in json data format to an external url in QML?
    Been goofing around with reading the sql data from the db but now I am stuck at populating the said data in a table view, any ideas or a workaround ?

    function readData()
        var db = readData()
        db.transaction(function (tx) {
            var results = tx.executeSql('SELECT rowid, firstname, secondname, date_of_birth FROM UserDetails order by rowid desc')
            for (var i = 0; i < results.rows.length; i++) {
    ListModel {
        id: myModel
        ListElement {
           firstname: " "
           secondname: " "
           date_of_birth: "" 
    TableView {
        id: myTable
        model: myModel
        TableViewColumn {
            role: "firstname"
            title: "First Name"
        TableViewColumn {
            role: "secondname"
            title: "Second Name"
        TableViewColumn {
            role: "date_of_birth"
            title: "Date of Birth"

  • @Levis
    from the code says that you read in the database but you have not captured values, deiv use sql codes capable of capturing database values and assigning values captured in listModel

  • Do you necessarily just stick to javascript?
    exposing a QSqlTableModel from the C++ side into QML would let you do what in just a few lines

  • @VRonin I have very little background knowledge of c++ that's why I am trying to avoid it all costs, but I love new adventures, how do I get started?

  • Lifetime Qt Champion


    You can start by the SQL Programming chapter in Qt's documentation.

Log in to reply