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. QSqlQueryModel::Data() Speed
Forum Update on Monday, May 27th 2025

QSqlQueryModel::Data() Speed

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 3.0k 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.
  • X Offline
    X Offline
    xjox
    wrote on 28 Mar 2012, 19:47 last edited by
    #1

    Hi guys, i have this code :
    @
    for (int i=0;i<cantidad;i++) //cantidad = 13k rows
    {

         ant= model->data(model->index(i,0)).toString(); //This line is slowing my App (5 seg 
                                                                                                           and is a lot)
    }
    

    @
    but for example when i do this:
    @
    for (int i=0;i<cantidad;i++) //cantidad = 13k rows
    {

         ant= model->data(model->index(5000,0)).toString();  //replace i for 5000
    
    }
    

    @
    The App run in less than 1s, what can be the cause? QSqlQueryModel bug?

    Any solution? :S

    Thx!

    Pd: Happen the same uing model->record(i).value(0).toString();

    [Edit: Added @-tags to code for formatting; mlong]

    1 Reply Last reply
    0
    • D Offline
      D Offline
      DerManu
      wrote on 28 Mar 2012, 20:12 last edited by
      #2

      Caching, probably. Once you've queried model->index(5000, 0)->data(), all further queries will only access an internal cache for the 5000th row and thus be much faster.
      You can verify this by timing each call with a high performance timer (~microseconds). If my guess is correct, the first call to data() (or index()) will be orders of magnitude slower than the subsequent.

      1 Reply Last reply
      0
      • X Offline
        X Offline
        xjox
        wrote on 28 Mar 2012, 20:18 last edited by
        #3

        But that slow is normal? how can i navigate in the model data then? i cant use variables in data/record func?

        1 Reply Last reply
        0
        • D Offline
          D Offline
          DerManu
          wrote on 28 Mar 2012, 20:27 last edited by
          #4

          If you said it takes 5 seconds, and you have 13000 rows, that means one query takes 0.3ms. that's not too bad. I don't know how QSqlQueryModel works internally, whether it actually queries the database when accessing indexes or only reads the internal model which was built with setQuery. If it actually queries the database everytime, then 0.3ms is actually quite good. Either way, if you want more performance, you'll need to get that data inside an intermediary cache that's specifically built to perform the accesses you want with high performance. You could either build that ontop of QSqlQueryModel or as a replacement. This might become alot of work, so make sure you have no other way around this, i.e. improved program logic that you don't even need to access 13000 indexes instantly.

          1 Reply Last reply
          0

          1/4

          28 Mar 2012, 19:47

          • 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