Results 1 to 7 of 7

Thread: Performance of Using QSqlTableModel

  1. #1
    Join Date
    Jan 2014
    Posts
    20
    Thanks
    2
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Performance of Using QSqlTableModel

    Hi,
    I use QSqlTableModel to access table stored in database,when I traverse and handle every row in one table which contains about 3500 rows, i find it need 3-4 seconds that is too slow. Is it normal and how to improve it?
    here is my code,
    Qt Code:
    1. int GetRecordCount()ï½›
    2. while(sqlTableModel.canFetchMore())
    3. ï½›
    4. sqlTableModel.fetchMore();
    5. }
    6. return sqlTableModel.rowCount();
    7. }
    8.  
    9. //traverse table
    10. for (i=0 ï¼›i<=GetRecordCount()ï¼›i++)
    11. ï½›
    12. QSqlRecord record = sqlTableModel.record(i);
    13. //...
    14. //...
    15. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,420
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Performance of Using QSqlTableModel

    Have you tried without the model overhead, i.e. using QSqlQuery, as suggested in the other thread?

    Cheers,
    _

  3. #3
    Join Date
    Jan 2014
    Posts
    20
    Thanks
    2
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Performance of Using QSqlTableModel

    Quote Originally Posted by anda_skoa View Post
    Have you tried without the model overhead, i.e. using QSqlQuery, as suggested in the other thread?

    Cheers,
    _
    Thanks first!
    I have tried using QSqlQuery as follows, but it was still very slow (need 5s to traverse about 3000 rows ), so why? Any ideas or suggestions?
    Qt Code:
    1. QSqlQuery query("SELECT * FROM tableA");
    2. while (query.next()) {
    3. doSomething();
    4. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,391
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Performance of Using QSqlTableModel

    What is "doSomething()" doing ?

  5. #5
    Join Date
    Jan 2014
    Posts
    20
    Thanks
    2
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Performance of Using QSqlTableModel

    Quote Originally Posted by stampede View Post
    What is "doSomething()" doing ?
    let's say as follows,
    Qt Code:
    1. void doSomething()
    2. {
    3. i++;
    4. }
    To copy to clipboard, switch view to plain text mode 
    so this mean that the "while" loop need too much time to execute itself. Now i notice that tableA has a field which store blob, once i don't select this field, then the speed become fast! Why and how to deal with blob with QSqlTableModel?
    thanks!

  6. #6
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,391
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Performance of Using QSqlTableModel

    BLOB is just a collection of bytes, it could be anything (for example image data), and it is up to the application to interpret it correctly. Looks like in your case it is quite large, so it affects the performance of your queries.

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

    Default Re: Performance of Using QSqlTableModel

    BLOBS are presented by Qt as a QVariant::ByteArray.

Similar Threads

  1. Replies: 8
    Last Post: 30th March 2011, 20:06
  2. QSqlTableModel and LIKE
    By JeanC in forum Qt Programming
    Replies: 2
    Last Post: 10th January 2008, 08:45
  3. QSqlTableModel Help pls
    By munna in forum Newbie
    Replies: 1
    Last Post: 7th March 2006, 19:40
  4. QSqlTableModel
    By raphaelf in forum Qt Programming
    Replies: 4
    Last Post: 4th March 2006, 12:35
  5. QSqlTableModel Help pls
    By munna in forum Newbie
    Replies: 1
    Last Post: 26th January 2006, 07:58

Tags for this Thread

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.