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. Count rows in QSqlQueryModel?
QtWS25 Last Chance

Count rows in QSqlQueryModel?

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 4.4k 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.
  • W Offline
    W Offline
    weblife
    wrote on last edited by
    #1

    Is there a way to count the amount of row a QSqlQueryModel holds without iterating through each record to see if it exist or would I be better off just making an additional QSqlQuery?

    I thought rowCount() would work but it has simply confused me.

    Brandon Clark
    www.themindspot.com

    1 Reply Last reply
    0
    • L Offline
      L Offline
      lgeyer
      wrote on last edited by
      #2

      It depends.

      If your database supports the QSqlDriver::QuerySize feature you can use rowCount() directly (otherwise it just returns the number of cached rows).

      If not, having a dedicated COUNT query might be the most performant solution.

      1 Reply Last reply
      0
      • T Offline
        T Offline
        tucnak
        wrote on last edited by
        #3

        Hi!

        I will give you an advice to search before posting - there were many posts here about it.

        1 Reply Last reply
        0
        • W Offline
          W Offline
          weblife
          wrote on last edited by
          #4

          @Lukas Geyer Thank you. I'll have to look into this but sounds like something that could be preventing this from working the way I thought. I have never worked with MySql, so I will have to read more on it. For some reason I have a feeling I will like the iteration time with a query but I also have to consider poor network speeds also.

          @tucnak Please don't respond to my post if they bother you. If you would like to please prove your point because I have looked. Provide a link to one of these many post. Should be easy as 1,2,3; right!

          Brandon Clark
          www.themindspot.com

          1 Reply Last reply
          0
          • L Offline
            L Offline
            lgeyer
            wrote on last edited by
            #5

            The MySQL driver should support QSqlDriver::QuerySize, so rowCount() should return the number of rows in the current query.

            1 Reply Last reply
            0
            • W Offline
              W Offline
              weblife
              wrote on last edited by
              #6

              @Lukas Geyer Thank you very much for your response again, your wisdom is vast.

              I still haven't come back to this but that is disconcerting because this means I am passing data wrong somewhere most likely if it isn't feeding me right. Will keep you updated when I come back to it I already have a idea what I need to do. Right now I am focusing on porting code to other OS's, fun...

              Brandon Clark
              www.themindspot.com

              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