Results 1 to 3 of 3

Thread: QSqlQueryModel speed problem

  1. #1
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default QSqlQueryModel speed problem

    Hello,

    I have a SQLite database with a large dataset, around 200000 rows.
    These rows are selected from the database with a QSqlQueryModel like this:

    Qt Code:
    1. QString q = QString("SELECT name FROM groups");
    2. model->setQuery(q);
    To copy to clipboard, switch view to plain text mode 

    This only returns the first 255 rows.
    Thus I need to use canFetchMore() and fetchMore() in a while loop to get all the rows.

    The disadvantage of that is that the userinterface becomes unresponsive for about 5 seconds. I like to solve that in such a way that all the rows are added without the userinterface freezing.



    If I don't use the query model and just do a QSqlQuery with the same SELECT command and using while(query.next()), I get all the rows in less than a second. This is my debug output:

    Time = QTime("11:35:26")
    Number of rows returned: -1
    Calculated rows: 192792
    Query is active: true
    Time = QTime("11:35:26")

    This is the code:
    Qt Code:
    1. QSqlQuery speedQuery;
    2. qDebug() << "Time = " << QTime::currentTime();
    3. speedQuery.exec("SELECT name FROM groups;");
    4.  
    5. int i = 0;
    6. while(speedQuery.next())
    7. {
    8. ++i;
    9. }
    10.  
    11. qDebug() << "Number of rows returned: " << speedQuery.size();
    12. qDebug() << "Calculated rows: " << i;
    13. qDebug() << "Query is active: " << speedQuery.isActive();
    14. qDebug() << "Time = " << QTime::currentTime();
    To copy to clipboard, switch view to plain text mode 

    How can I make QSqlQueryModel as fast as QSqlQuery?
    I think the speed differences are in inserting rows in the model. Is there a way to speed this up?

    If I don't use the canFetchMore() - fetchMore() loop, then there's no speed problem, but the slider on the listview doesn't work correct. If I drag the slider to the bottom, more items are fetched and the more I go down, the slower it becomes.

    Can anyone give me any pointers on how to load all the items of the database in the listview without freezing the userinterface for a couple of seconds?

  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 speed problem

    If you load all items at once, you're get a huge lag at the beginning.

    If you want, you can make a lazy initialization of the model in the background by an external thread.

    You can get some info on that here: http://blog.wysota.eu.org/index.php/...remote-models/

  3. #3
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: QSqlQueryModel speed problem

    Thanks wysota,

    That's exactly what I was looking for.

Similar Threads

  1. QSqlQueryModel write subclass
    By skuda in forum Qt Programming
    Replies: 6
    Last Post: 29th October 2007, 16:18
  2. QTcpSocket speed problem
    By benelgiac in forum Qt Programming
    Replies: 4
    Last Post: 1st May 2007, 13:50
  3. Replies: 16
    Last Post: 7th March 2006, 15:57

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.