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. Qt 5.14.2 QSqlQuery does not read all rows into QTableView [SOLVED]
Forum Updated to NodeBB v4.3 + New Features

Qt 5.14.2 QSqlQuery does not read all rows into QTableView [SOLVED]

Scheduled Pinned Locked Moved Unsolved General and Desktop
10 Posts 4 Posters 1.3k Views 2 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.
  • A Offline
    A Offline
    ad5xj
    wrote on last edited by ad5xj
    #1

    I know I have seen this somewhere before but I simply cannot find it now. So I will ask a newbie question.

    I have created a SQL Query and made it a QSQLMode for a QTableView. It has a large result set that is displayed in the QTableView correctly.

    However, I have discovered it only displays about 300 rows or so until scrolling down to the last record displayed. Then about that many more are added but do not follow the formatting of the previous rows as far as formatting like row height. More scrolling produces more rows, etc until all the query rows are retrieved.

    My question is how to get all rows in the query and have them all shown in the QTableView without having to scroll to the last displayed row to load more.

    The use of the QSqlModel speeds the load and view of large data queries far faster than other methods and except for this problem have a superior performance over any other method I have used this far.

    Does anyone remember how this is done? Or can someone advise what to do?

    Sorry for such a newbie question.

    Ken AD5XJ

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

      Hi,

      You are likely looking for canFetchMore and its friends.

      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
      • A ad5xj

        I know I have seen this somewhere before but I simply cannot find it now. So I will ask a newbie question.

        I have created a SQL Query and made it a QSQLMode for a QTableView. It has a large result set that is displayed in the QTableView correctly.

        However, I have discovered it only displays about 300 rows or so until scrolling down to the last record displayed. Then about that many more are added but do not follow the formatting of the previous rows as far as formatting like row height. More scrolling produces more rows, etc until all the query rows are retrieved.

        My question is how to get all rows in the query and have them all shown in the QTableView without having to scroll to the last displayed row to load more.

        The use of the QSqlModel speeds the load and view of large data queries far faster than other methods and except for this problem have a superior performance over any other method I have used this far.

        Does anyone remember how this is done? Or can someone advise what to do?

        Sorry for such a newbie question.

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by JonB
        #3

        @ad5xj
        As @SGaist has just said. The "about 300 rows" is because internal Qt code implementation fetches 256 rows at a time from SQL database. You want to call fetchMore() while canFetchMore() returns true to fetch them all in one go. Initial delay in return for smoother performance.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          ad5xj
          wrote on last edited by
          #4

          It seems from the documentation that this method works only if the database reports the correct query size (rows). In the case of SQLite 3 it does not.

          Ken AD5XJ

          JonBJ B 2 Replies Last reply
          0
          • A ad5xj

            It seems from the documentation that this method works only if the database reports the correct query size (rows). In the case of SQLite 3 it does not.

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by JonB
            #5

            @ad5xj
            Have you actually tried it nonetheless? The example at https://doc.qt.io/qt-5/qsqlquerymodel.html#fetchMore implies to me that it should work. For example, https://stackoverflow.com/questions/26369420/when-or-how-to-use-fetchmore-on-qsqltablemodel-with-a-sqlite-database-for-rowc is using that on SQLite. So far as I know, that is what QTableView will be using, and it corresponds to the new rows you see being added.

            1 Reply Last reply
            0
            • A ad5xj

              It seems from the documentation that this method works only if the database reports the correct query size (rows). In the case of SQLite 3 it does not.

              B Offline
              B Offline
              Bonnie
              wrote on last edited by
              #6

              @ad5xj said in Qt 5.14.2 QSqlQuery does not read all rows into QTableView:

              It seems from the documentation that this method works only if the database reports the correct query size (rows). In the case of SQLite 3 it does not.

              No, the doc says that it only affects databases that don't report back the size of a query

              A 1 Reply Last reply
              0
              • B Bonnie

                @ad5xj said in Qt 5.14.2 QSqlQuery does not read all rows into QTableView:

                It seems from the documentation that this method works only if the database reports the correct query size (rows). In the case of SQLite 3 it does not.

                No, the doc says that it only affects databases that don't report back the size of a query

                A Offline
                A Offline
                ad5xj
                wrote on last edited by
                #7

                @Bonnie

                No, the doc says that it only affects databases that don't report back the size of a query
                ``
                Not understanding what you are saying here. 
                
                I said in the quote you included that SQLIte 3 DOES NOT report query size accurately. You can move to the last record and the size will update. But it only applies the record count to the segment that has been loaded (e.g. 256 records), not the entire query result. 
                
                I am attempting to get all the records in the query result not just the first few. The query my retrieve several thousand records.

                Ken AD5XJ

                B JonBJ 2 Replies Last reply
                0
                • A ad5xj

                  @Bonnie

                  No, the doc says that it only affects databases that don't report back the size of a query
                  ``
                  Not understanding what you are saying here. 
                  
                  I said in the quote you included that SQLIte 3 DOES NOT report query size accurately. You can move to the last record and the size will update. But it only applies the record count to the segment that has been loaded (e.g. 256 records), not the entire query result. 
                  
                  I am attempting to get all the records in the query result not just the first few. The query my retrieve several thousand records.
                  B Offline
                  B Offline
                  Bonnie
                  wrote on last edited by Bonnie
                  #8

                  @ad5xj
                  I mean the documentation of the method "canFetchMore" and "fetchMore" says that the two methods only have affect in databases that don't has the feature of QSqlDriver::QuerySize. So they work with SQLite 3.

                  1 Reply Last reply
                  1
                  • A ad5xj

                    @Bonnie

                    No, the doc says that it only affects databases that don't report back the size of a query
                    ``
                    Not understanding what you are saying here. 
                    
                    I said in the quote you included that SQLIte 3 DOES NOT report query size accurately. You can move to the last record and the size will update. But it only applies the record count to the segment that has been loaded (e.g. 256 records), not the entire query result. 
                    
                    I am attempting to get all the records in the query result not just the first few. The query my retrieve several thousand records.
                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on last edited by
                    #9

                    @ad5xj
                    I asked before:

                    Have you actually tried it [the canFetchMore()-fetchMore() loop] nonetheless?

                    ?

                    1 Reply Last reply
                    0
                    • A Offline
                      A Offline
                      ad5xj
                      wrote on last edited by
                      #10

                      Thanks JonB for the link to the solution.

                      I changed my code to be like the link and that did it. Problem solved.

                      Ken AD5XJ

                      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