Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    QSqlQueryModel::Data() Speed

    General and Desktop
    2
    4
    2714
    Loading More Posts
    • 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
      xjox last edited by

      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 Reply Quote 0
      • D
        DerManu last edited by

        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 Reply Quote 0
        • X
          xjox last edited by

          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 Reply Quote 0
          • D
            DerManu last edited by

            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 Reply Quote 0
            • First post
              Last post