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 view whole data from SQLlite table

How view whole data from SQLlite table

Scheduled Pinned Locked Moved Solved QML and Qt Quick
qml tableviewsqlite3qsqlquerymodel
4 Posts 3 Posters 323 Views
  • 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.
  • D Offline
    D Offline
    Damian7546
    wrote on 15 Jun 2024, 10:49 last edited by
    #1

    I have a problem with view data form database.
    In my QML application I would like to view whole data from SQLite table. Currently only displayed one (first) column, but in my table I have three of them

    My file main.cpp is below:

    DbManager db("C:\\sqlite\\db\\database.db");
    
    QSqlQueryModel *someSqlModel = new QSqlQueryModel();
    someSqlModel->setQuery("SELECT * FROM sale");
    
    engine.rootContext()->setContextProperty("datamodel", someSqlModel);
    

    My file main.qml is below:

    Rectangle {
            ListView {
                anchors {
                    left: parent.left
                    top: parent.top
                    leftMargin: 50
                    topMargin: 50
                }
                width: 800
                height: 1000
                model: datamodel
                delegate: Row {
                    Rectangle {
                        width: 200
                        height: 40
                        Text {
                            anchors.fill: parent
                            text: display
                        }
                    }
                }
            }
        }
    

    Any idea what I do wrong ?

    D 1 Reply Last reply 15 Jun 2024, 18:27
    0
    • D Damian7546
      15 Jun 2024, 10:49

      I have a problem with view data form database.
      In my QML application I would like to view whole data from SQLite table. Currently only displayed one (first) column, but in my table I have three of them

      My file main.cpp is below:

      DbManager db("C:\\sqlite\\db\\database.db");
      
      QSqlQueryModel *someSqlModel = new QSqlQueryModel();
      someSqlModel->setQuery("SELECT * FROM sale");
      
      engine.rootContext()->setContextProperty("datamodel", someSqlModel);
      

      My file main.qml is below:

      Rectangle {
              ListView {
                  anchors {
                      left: parent.left
                      top: parent.top
                      leftMargin: 50
                      topMargin: 50
                  }
                  width: 800
                  height: 1000
                  model: datamodel
                  delegate: Row {
                      Rectangle {
                          width: 200
                          height: 40
                          Text {
                              anchors.fill: parent
                              text: display
                          }
                      }
                  }
              }
          }
      

      Any idea what I do wrong ?

      D Offline
      D Offline
      Damian7546
      wrote on 15 Jun 2024, 18:27 last edited by
      #2

      In the above code just change List View to TableView

      I have other problem . When the someSqlModel I have in main.cpp everything works ok.
      Now I moved someQglModel to another class, and this class I exposed to QML:

        engine.rootContext()->setContextProperty("dbManager",dbManager);
      

      And in my QML code I try get model to TableView by:

      model: dbManager.someSqlModel
      

      but it doesn't work, any idea ?

      1 Reply Last reply
      0
      • S Offline
        S Offline
        SGaist
        Lifetime Qt Champion
        wrote on 15 Jun 2024, 19:07 last edited by
        #3

        Hi,

        You should share the code of your DbManager class.

        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
        1
        • D Offline
          D Offline
          dheerendra
          Qt Champions 2022
          wrote on 17 Jun 2024, 05:48 last edited by
          #4

          May be you missed creating the someSqlModel object itself ? Is someSqlModel local object ?

          Dheerendra
          @Community Service
          Certified Qt Specialist
          http://www.pthinks.com

          1 Reply Last reply
          0
          • D Damian7546 has marked this topic as solved on 30 Sept 2024, 12:27

          1/4

          15 Jun 2024, 10:49

          • Login

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