Results 1 to 8 of 8

Thread: QTableView performance

  1. #1
    Join Date
    Dec 2009
    Posts
    52
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default QTableView performance

    Hello,

    I have this abstract table model

    Qt Code:
    1. class log_q_item_model : public QAbstractTableModel {
    2. Q_OBJECT
    3. public:
    4. log_q_item_model(const log_ptr& log) /// log_ptr is boost:;shared_ptr< std::vector< std::pair<date, double> > >
    5. : log_(log)
    6. {}
    7.  
    8. int rowCount(const QModelIndex&) const
    9. {
    10. return log_->size();
    11. }
    12. int columnCount(const QModelIndex&) const
    13. {
    14. return 2;
    15. }
    16. QVariant data(const QModelIndex& index, int role) const
    17. {
    18. if (index.isValid() && index.row()>=0 && static_cast<size_t>(index.row())<log_->size() && role==Qt::DisplayRole) {
    19. const logentry_t& e = (*log_)[index.row()];
    20.  
    21. return (index.column()==0)?
    22. QString(boost::gregorian::to_simple_string(e.first).c_str()):
    23. QString::number(e.second,'f',2);
    24. }
    25.  
    26. return QVariant();
    27. }
    28.  
    29. QVariant headerData(int section, Qt::Orientation orientation, int role) const
    30. {
    31. if (role != Qt::DisplayRole)
    32. return QVariant();
    33.  
    34. if (orientation == Qt::Horizontal) {
    35. switch (section) {
    36. case 0:
    37. return tr("Date");
    38.  
    39. case 1:
    40. return tr("Logname");
    41.  
    42. default:
    43. return QVariant();
    44. }
    45. }
    46.  
    47. return QVariant();
    48. }
    49. private:
    50. const log_ptr log_;
    51. };
    To copy to clipboard, switch view to plain text mode 

    that use with a QTableView to display about 10 000 entries.

    It is a bit slow to display? I know because I filled up the log vector before without displaying it and the GUI was faster.
    I would appreciate any hints as to where to optimize this class?

    Regards,

  2. #2
    Join Date
    Feb 2010
    Posts
    96
    Thanks
    4
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTableView performance

    Could you thread it in blocks of 1,000? Or thread the load time so that the table fills as new entries pass the thread .. kinda like when you load a new large music library.

    I have not used a Table in Qt yet.

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

    Quote Originally Posted by hml View Post
    I know because I filled up the log vector before without displaying it and the GUI was faster.
    What do you mean by "before" and "faster"? What was faster than what?
    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.


  4. #4
    Join Date
    Dec 2009
    Posts
    52
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTableView performance

    Initially, after calculating the log vector, I plotted its elements on a 2D plot with qwtplot library.
    That was fast.
    I then added the QTableView and display it in a grid layout alongside the plot.
    Now the window takes much longer to show (3seconds)

    The vector is calculated once and the only difference with before is the addition of the QTableView.
    I deduce that my AbstractTableModel must be wrongly implemented,

    rds,

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

    How do you add elements to the table? Can we see the code?
    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.


  6. #6
    Join Date
    Dec 2009
    Posts
    52
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTableView performance

    I don't understand.
    I only create a new instance of

    Qt Code:
    1. class log_q_table_view : public QTableView {
    2. public:
    3. log_q_table_view(const log_ptr& log, QWidget* parent =0)
    4. {
    5. setEditTriggers(QAbstractItemView::NoEditTriggers);
    6. setModel(new log_q_item_model(log));
    7. verticalHeader()->setResizeMode(QHeaderView::ResizeToContents);
    8. horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents);
    9. }
    10. };
    To copy to clipboard, switch view to plain text mode 

    In the GUI, I create a new instance of log_q_table_view, and then add it to the grid layout for display.

    The vector pointed to by the log shared pointer has existed for a long time at that stage,

    Was this what you meant?

    Thank you!

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

    Bah... sorry, I meant to ask how do you add elements to the table model. Sorry for not being clear. I see you are passing a copy of the data to the table. This is completely unnecessary (http://blog.wysota.eu.org/index.php/...ta-redundancy/) but I don't think this will slow down your app so much. I'd say the problem is caused by the calculations you are doing in data(). It would be wise to get rid of them and then run your application under a profiler to find the bottle neck - right now we're just shooting blind.
    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
    Posts
    52
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTableView performance

    all right i will profile the GUI.
    There are over 10000 entries. so data() would be called at least that many times.

    In data(), I have to check that the QModelIndex is valid and that the row is valid and that the role is DisplayRole, don't I?

    I see you are passing a copy of the data to the table. This is completely unnecessary
    I am copying a log_ptr. But that is just a boost::shared_ptr and does not involve deep copying of the whole vector, it's just a pointer.
    And the model just interprets my internal data structure to return QVariants, I follow what you say in the blog I think,

    thanks,

Similar Threads

  1. QTableView - resizeRowsToContents() poor performance
    By antarctic in forum Qt Programming
    Replies: 2
    Last Post: 11th December 2009, 13:13
  2. QTableView performance
    By Anchor in forum Qt Programming
    Replies: 7
    Last Post: 2nd June 2009, 10:15
  3. Performance with QTableView and QAbstractTableModel
    By MBex in forum Qt Programming
    Replies: 3
    Last Post: 25th February 2009, 08:04
  4. QTableView Performance Problem on Windows
    By umitoz in forum Qt Programming
    Replies: 1
    Last Post: 31st August 2007, 16:47
  5. Replies: 9
    Last Post: 23rd November 2006, 11:39

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.