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.append({
                    id:results.rows.item(i).rowid,
                    checked:"",
                    firstname:results.rows.item(i).firstname,
                    secondname:results.rows.item(i).secondname,
                    date_of_birth:results.rows.item(i).date_of_birth
                })
            }
        })
    }
    
    
    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
    Hi,
    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


  • Qt Champions 2018

    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

    Hi,

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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.