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?
Forum Updated to NodeBB v4.3 + New Features

Count rows in QSqlQueryModel?

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 4.4k 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.
  • W Offline
    W Offline
    weblife
    wrote on 27 Aug 2012, 22:51 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 28 Aug 2012, 06:05 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 28 Aug 2012, 10:29 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 1 Sept 2012, 19:13 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 3 Sept 2012, 04:52 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 3 Sept 2012, 17:54 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

              5/6

              3 Sept 2012, 04:52

              • Login

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