Results 1 to 10 of 10

Thread: need faster QTableView performance

  1. #1
    Join Date
    Jun 2012
    Posts
    63
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default need faster QTableView performance

    What kind of possibilities there are to get faster QTableView performance when adding big amount of rows. I want to add say, 10 000 rows in "batch" and then display it to user. It seems too slow for me. I want to know what is the fastest way to add "batch" data of large amounts.

    I'm using QTableView and setting QStandardItemModel as model.

    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. QApplication app(argc, argv);
    4.  
    5. QStandardItemModel model(50, 3);
    6. for (int i = 0; i < model.rowCount(); ++i) {
    7. for (int j = 0; j < model.columnCount(); ++j) {
    8. QStandardItem *item = new QStandardItem(QString("%1, %2").arg(i).arg(j));
    9. model.setItem(i, j, item);
    10. }
    11. }
    12.  
    13. view.setModel(&model);
    14. view.setVerticalScrollBar(new WideScrollBar(&view));
    15. view.show();
    16.  
    17. return app.exec();
    To copy to clipboard, switch view to plain text mode 

  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: need faster QTableView performance

    Use a custom model instead of QStandardItemModel. As a last resort disable updates of the view or temporarily block signals from the model.
    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
    Jun 2012
    Posts
    63
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: need faster QTableView performance

    Ok, I guess that I would need to implement my own class for data storage and re-implement my own function something like 'setAllData(MyData*) that sets all the data at once ?

  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: need faster QTableView performance

    More likely you should have a function for appending a batch of data at once. This doesn't have to be "all" data.
    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
    May 2012
    Posts
    136
    Thanks
    2
    Thanked 27 Times in 24 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: need faster QTableView performance

    For a custom table model you can implement insertrows
    call beginInsertRows(parentIndex, first, last);
    add all the rows you need
    call endInsertRows()

    this should only update once after finishing inserting rows.

  6. #6
    Join Date
    Jun 2012
    Posts
    63
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: need faster QTableView performance

    Quote Originally Posted by wysota View Post
    More likely you should have a function for appending a batch of data at once. This doesn't have to be "all" data.
    Quote Originally Posted by StrikeByte View Post
    For a custom table model you can implement insertrows
    call beginInsertRows(parentIndex, first, last);
    add all the rows you need
    call endInsertRows()

    this should only update once after finishing inserting rows.
    Thanks, what do you suggest for data implementation class (QVector, QList, etc..) if I only need new function in my derived QAbstractItemModel to fill data at once ?

  7. #7
    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: need faster QTableView performance

    Quote Originally Posted by phenoboy View Post
    Thanks, what do you suggest for data implementation class (QVector, QList, etc..) if I only need new function in my derived QAbstractItemModel to fill data at once ?
    It really depends on your data and how your model is to behave. QList is usually a good first approach as the model is linear anyway.
    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.


  8. #8
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: need faster QTableView performance

    I don't have a ton of experience writing models, but the first one I wrote used QList... Worked fine until I started using larger result sets and added the ability to sort by any column.

    I rewrote the model to use QVector and QSortFilterProxyModel which greatly improved the speed for sorting operations. While I never did benchmark QList vs QVector, I suspect the biggest improvement was due to the QSortFilterProxyModel implementation, not necessarily the difference between QList and QVector, but I never cared enough to benchmark the difference.

    If you also have sorting requirements, you might want to implement QSortFilterProxyModel.

    Good luck.

  9. #9
    Join Date
    Jun 2012
    Posts
    63
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: need faster QTableView performance

    Quote Originally Posted by jthomps View Post
    I don't have a ton of experience writing models, but the first one I wrote used QList... Worked fine until I started using larger result sets and added the ability to sort by any column.

    I rewrote the model to use QVector and QSortFilterProxyModel which greatly improved the speed for sorting operations. While I never did benchmark QList vs QVector, I suspect the biggest improvement was due to the QSortFilterProxyModel implementation, not necessarily the difference between QList and QVector, but I never cared enough to benchmark the difference.

    If you also have sorting requirements, you might want to implement QSortFilterProxyModel.

    Good luck.
    Thanks, I use QSortFilterProxyModel in my current implementation and it is a must to have. Basically I would be fine with QStandardItemModel but I only need one additional function to make large amounts of rows much faster. I am thinking how to design my own model so that I could use QStandardItemModel as backend to represent data and use QStandardItem classes as cell items. They're nice as they give you basic features, checkboxes, foreground and background colors, etc..

  10. #10
    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: need faster QTableView performance

    Quote Originally Posted by jthomps View Post
    While I never did benchmark QList vs QVector, I suspect the biggest improvement was due to the QSortFilterProxyModel implementation, not necessarily the difference between QList and QVector, but I never cared enough to benchmark the difference.
    The only practical difference between those two classes is that the vector only grows at the end while QList can grow from both ends which makes it faster to insert elements at the beginning or in the middle of the sequence.
    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.


Similar Threads

  1. QTableView performance
    By hml in forum Newbie
    Replies: 7
    Last Post: 16th March 2010, 16:14
  2. QTableView - resizeRowsToContents() poor performance
    By antarctic in forum Qt Programming
    Replies: 2
    Last Post: 11th December 2009, 13:13
  3. QTableView performance
    By Anchor in forum Qt Programming
    Replies: 7
    Last Post: 2nd June 2009, 10:15
  4. Performance with QTableView and QAbstractTableModel
    By MBex in forum Qt Programming
    Replies: 3
    Last Post: 25th February 2009, 08:04
  5. Replies: 9
    Last Post: 23rd November 2006, 11:39

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.