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. do we have example show how to edit and display sqlite data in tableview in QML?
Forum Updated to NodeBB v4.3 + New Features

do we have example show how to edit and display sqlite data in tableview in QML?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
5 Posts 3 Posters 343 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.
  • Q Offline
    Q Offline
    QtTester
    wrote on last edited by
    #1

    some article are very old ,my qt version is 6.9.3+vs2022, the tableview component is also changed frequently, finally i cannot find a correct example to demostrate the sql database read and write in qml.

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

      Hi,

      From a quick look at the documentation, i think you can start with:

      • https://doc.qt.io/qt-6/qtquick-modelviewsdata-modelview.html#changing-model-data on how to configure your delegate to be read/write
        And for the model:
      • https://wiki.qt.io/How_to_Use_a_QSqlQueryModel_in_QML to give you a base for a read-only model
        Implement the setData for your custom model

      Note I haven't done that yet, it's just putting some elements together.

      Hope it helps

      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
      • Q Offline
        Q Offline
        QtTester
        wrote on last edited by
        #3

        here is my code ,i open the database and add data manualy ,but i think the model does not connect to the database, so no data is displayed in the view.

        wechat_2025-10-15_085631_078.jpg

        main.qml

        import QtQuick
        import QtQuick.Effects
        import QtQuick.Controls
        import QtQuick.Layouts
        import Charts
        
        ApplicationWindow {
            id:root
            width: 640
            height: 480
            visible: true
            color: 'white'
            title: qsTr("Hello World")
        
            footer: ToolBar {
                id: statusBar
                height: 30
        
                Label {
                    id: statusLabel
                    anchors.fill: parent
                    anchors.leftMargin: 10
                    verticalAlignment: Text.AlignVCenter
                    text: "ready"
                }
            }
        
            // table
            SqlTable{
                anchors.fill: parent
            }
        
        }
        
        
        Q 1 Reply Last reply
        0
        • Q QtTester

          here is my code ,i open the database and add data manualy ,but i think the model does not connect to the database, so no data is displayed in the view.

          wechat_2025-10-15_085631_078.jpg

          main.qml

          import QtQuick
          import QtQuick.Effects
          import QtQuick.Controls
          import QtQuick.Layouts
          import Charts
          
          ApplicationWindow {
              id:root
              width: 640
              height: 480
              visible: true
              color: 'white'
              title: qsTr("Hello World")
          
              footer: ToolBar {
                  id: statusBar
                  height: 30
          
                  Label {
                      id: statusLabel
                      anchors.fill: parent
                      anchors.leftMargin: 10
                      verticalAlignment: Text.AlignVCenter
                      text: "ready"
                  }
              }
          
              // table
              SqlTable{
                  anchors.fill: parent
              }
          
          }
          
          
          Q Offline
          Q Offline
          QtTester
          wrote on last edited by
          #4

          cannot post my model ,it says flaged as spam by Akismet.com, so i replace with picture

          wechat_2025-10-15_091855_294.jpg

          wechat_2025-10-15_091357_511.jpg
          wechat_2025-10-15_091415_726.jpg
          wechat_2025-10-15_091437_846.jpg

          1 Reply Last reply
          0
          • GrecKoG Offline
            GrecKoG Offline
            GrecKo
            Qt Champions 2018
            wrote on last edited by
            #5

            QSqlTableModel + TableView sounds like what you need

            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