Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QTableView Empty ?

QTableView Empty ?

Scheduled Pinned Locked Moved Unsolved General and Desktop
qtableviewqsqltablemodelsqlite3
18 Posts 4 Posters 3.3k 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.
  • R R-P-H

    @mrjj No there is no database...I get given the table of results in "records" which have already been populated from a previous data pull.

    I just want to easily display them in a table without manually looping through fields...

    Do I need to initialise a dummy database or something ?

    SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #8

    @R-P-H said in QTableView Empty ?:

    @mrjj No there is no database...I get given the table of results in "records" which have already been populated from a previous data pull.

    I just want to easily display them in a table without manually looping through fields...

    Do I need to initialise a dummy database or something ?

    Hi,

    If you don't have any database then why are you using a SQL model ?

    Before going further, do you want to store your data in a database ? Or just show them in a tabular fashion ?

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

    R 1 Reply Last reply
    1
    • SGaistS SGaist

      @R-P-H said in QTableView Empty ?:

      @mrjj No there is no database...I get given the table of results in "records" which have already been populated from a previous data pull.

      I just want to easily display them in a table without manually looping through fields...

      Do I need to initialise a dummy database or something ?

      Hi,

      If you don't have any database then why are you using a SQL model ?

      Before going further, do you want to store your data in a database ? Or just show them in a tabular fashion ?

      R Offline
      R Offline
      R-P-H
      wrote on last edited by
      #9

      @SGaist Mainly I just want to display it in a tabular fashion but without the work involved in looping through each QSqlRecord and corresponding field.

      Considering the data is stored in QSqlRecords I thought using QTableView would be the easiest way to achieve that...

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

        You still need a valid database to insert your records in.

        You can use the SQLite plugin for that and the in memory database if you don't want to store in on disk.

        Note that you still have to create the table before putting something in it.

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

        R 1 Reply Last reply
        2
        • SGaistS SGaist

          You still need a valid database to insert your records in.

          You can use the SQLite plugin for that and the in memory database if you don't want to store in on disk.

          Note that you still have to create the table before putting something in it.

          R Offline
          R Offline
          R-P-H
          wrote on last edited by
          #11

          @SGaist Do you mean creating a database and database table in code ?

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

            Before going further, one thing is not clear... Where do you get these records from ?

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

            R 1 Reply Last reply
            1
            • SGaistS SGaist

              Before going further, one thing is not clear... Where do you get these records from ?

              R Offline
              R Offline
              R-P-H
              wrote on last edited by
              #13

              @SGaist From a sqlite database on file...The output from that function is a QVector of QSqlRecords and I didn't really want to mess with that function but now I have the need to display the data neatly in my GUI.

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

                Then why not use a QSqlTableModel ?
                Or a QSqlQueryModel ?

                There would be no need for that vector of records.

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

                R 1 Reply Last reply
                1
                • SGaistS SGaist

                  Then why not use a QSqlTableModel ?
                  Or a QSqlQueryModel ?

                  There would be no need for that vector of records.

                  R Offline
                  R Offline
                  R-P-H
                  wrote on last edited by
                  #15

                  @SGaist Let's say I only get passed the records and can't access the DB file myself... Obviously the function could be changed to pass the results in that format already but right now it's in the form of QtSqlRecords...

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

                    So you can either do as suggested and create that minimal database with the table needed to show your data or use a QStandardItemModel where you put the content of all these records.

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

                    R 1 Reply Last reply
                    0
                    • SGaistS SGaist

                      So you can either do as suggested and create that minimal database with the table needed to show your data or use a QStandardItemModel where you put the content of all these records.

                      R Offline
                      R Offline
                      R-P-H
                      wrote on last edited by
                      #17

                      @SGaist For QStandardModel I don't see a way to directly make use of my QtSqlRecords, does that mean I have to loop manually through the fields ? Would it still be shown in QTableView ?

                      For making a minimal database do I need to set a database name?

                      I will try to implement the other model on the actual dB as well....

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

                        Yes you do, or you can make your own custom QAbstractTableModel that will return the content of your vector of records.

                        Yes you do. However you can use an in-memory database if you don't want to have another database in a file.

                        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
                        3

                        • Login

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