Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. How do I populate the table with the sql data
Forum Updated to NodeBB v4.3 + New Features

How do I populate the table with the sql data

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
5 Posts 4 Posters 828 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Levis
    wrote on last edited by
    #1

    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"
        }
    }
    
    D 1 Reply Last reply
    0
    • L Levis

      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"
          }
      }
      
      D Offline
      D Offline
      Domenico
      wrote on last edited by
      #2

      @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

      1 Reply Last reply
      0
      • VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by
        #3

        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

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        L 1 Reply Last reply
        1
        • VRoninV VRonin

          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

          L Offline
          L Offline
          Levis
          wrote on last edited by
          #4

          @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?

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Hi,

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

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved