Results 1 to 6 of 6

Thread: QSqlQueryModel tweaks?

  1. #1
    Join Date
    Aug 2007
    Posts
    275
    Thanks
    28
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default QSqlQueryModel tweaks?

    I have an SQL stement that will return millions of record ie
    Qt Code:
    1. select * from myTable
    To copy to clipboard, switch view to plain text mode 

    i noticed that this will take sometime to see it on my QTableView. now my question is . Where can i possibly tweak it to make it faster?

    My opinion:

    I think QSqlQueryModel is caching just 256 records at a time , and model to view will take no time at all. I think its really the database that is taking the time to "build" those records for me. If theres in any other path that i can work on to make it a bit faster please enlighten me...

    by the way my database is MS SQL

    baray98

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QSqlQueryModel tweaks?

    Use QSqlTableModel, there is a chance it will be faster. If not then you can't use such a simple model and need to ask the database for just part of the data at a time. Also have a look at this: http://blog.wysota.eu.org/index.php/...remote-models/
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Aug 2007
    Posts
    275
    Thanks
    28
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QSqlQueryModel tweaks?

    wysota,

    may i know why you think QSqlTableModel would be faster than QSqlQueryModel if you don't mind.

    baray98

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QSqlQueryModel tweaks?

    As far as I remember the query model downloads all rows from the query result at once and the table model fetches rows as they are needed but I may be wrong.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QSqlQueryModel tweaks?

    I found the same behaviour with QSqlTableModel (which is built atop QSqlQueryModel anyway) on Sqlite databases. The QTableView displays the first 255 (model's QSQL_PREFETCH value) rows and scales its vertical scroll bar for that number (the model is returning a rowCount()==255). When you drag the scroller down you get a long pause as the model fetches another 255 rows and rescales the scroll bar. It will keep doing this until all rows are fetched. The only way I found to have smooth end-to-end scrolling was to do:
    Qt Code:
    1. while (model->canFetchMore()) model->fetchMore();
    To copy to clipboard, switch view to plain text mode 
    which is acceptable for a few thousand rows but not (probably) a few million.

  6. #6
    Join Date
    Aug 2007
    Posts
    275
    Thanks
    28
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QSqlQueryModel tweaks?

    I visited your blog http://blog.wysota.eu.org/index.php/...remote-models/ and tried your remotemodel and I think its a cool idea for my case and you mentioned you've tried it in some SQL database too.

    If its not too much I am wondering if you can share a snippet of your model accessing SQL database so I can test if it will improve my problem.

    baray98

Similar Threads

  1. QSqlQueryModel data update
    By psi in forum Qt Programming
    Replies: 4
    Last Post: 20th July 2012, 03:59
  2. how can I refresh QSqlQueryModel?
    By hashb in forum Qt Programming
    Replies: 3
    Last Post: 20th June 2009, 03:39
  3. QSqlQueryModel fetchMore
    By skuda in forum Qt Programming
    Replies: 0
    Last Post: 17th July 2008, 19:42
  4. QSqlQueryModel speed problem
    By tbscope in forum Qt Programming
    Replies: 2
    Last Post: 23rd March 2008, 11:31
  5. QSqlQueryModel + set Write
    By raphaelf in forum Qt Programming
    Replies: 7
    Last Post: 5th June 2006, 08:55

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.