Note that there are some explanatory texts on larger screens.

plurals
  1. POQAbstractTableModel::data method is called too many times
    primarykey
    data
    text
    <p>I need a table GUI control that is able to quickly add and show around 100'000 items. For this reason, "virtual" table control is needed, that loads and shows only visible items. I tried QTableView and QAbstractTableModel:</p> <pre><code>class MyModel : public QAbstractTableModel { public: MyModel(QObject * parent, IDataSource* dataSource) : QAbstractTableModel(parent), m_dataSource(dataSource) {} int rowCount(const QModelIndex&amp; parent = QModelIndex()) const { return m_dataSource-&gt;rowCount(); } int columnCount(const QModelIndex&amp; parent = QModelIndex()) const { return 3; } QVariant data(const QModelIndex&amp; index, int role = Qt::DisplayRole) const { if (role == Qt::DisplayRole) { return m_dataSource-&gt;cell(index.row(), index.column()); } return QVariant(); } bool addItem() { beginInsertRows(QModelIndex(), rowCount(), rowCount()); endInsertRows(); return true; } private: IDataSource* m_dataSource; }; ... MyModel* model = new MyModel(this, this); m_ui.tableView-&gt;setModel(model); m_ui.tableView-&gt;show(); </code></pre> <p>The problem is that MyModel::data() is called when adding new items out of visible area. And this makes a big slow in performance. This is my test scenario to be more specific:</p> <ol> <li>View is created with only 5 elements that can be visible at one time.</li> <li>I add 20 items with MyModel::addItems.</li> <li>MyModel::data is called for all visible items.</li> <li>MyModel::data continues to be called for visible items (1...5) when items 6, 7, 9 ... 20 are added.</li> </ol> <p>I was thinking maybe this can be caused by vertical scrollbar that is redrawn when adding new items and seems to make all QListView redraw. But after hiding vertical scrollbar the issue remained. Please suggest.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload