speed up QTableview with large data

  • Hi everyone,
    I'm using QTableview to display my data, around 30k rows, each row have 150 columns and it take around 3 min to load completed.
    Currently I have setup my QTableview with code below:

    int col = 0;
    QStandardItemModel *itemModel = new QStandardItemModel(item.count(), 150, this);
    itemModel ->setHorizontalHeaderItem(col++, new QStandardItem(QString("Name")));
    itemModel ->setHorizontalHeaderItem(col++, new QStandardItem(QString("Last col")));
    for(int row = 0; row < item.count(); row++)
        col = 0;
        itemModel ->setItem(row, col++, new QStandardItem("Item name"));
    ui->tbv_item->setModel(itemModel );

    I need to display all rows, col to users. Any idea how to speed up it?

  • Qt Champions 2017

    since it is huge data u will hit these issues. I suggest you develop your own model with custom datastructure. You many not be showing all the data at one shot. So load only the required data into model for display.

  • Lifetime Qt Champion

    as already suggested a custom model might be the cure
    This talks about huge datasets

  • @oxycoder

    It is true that QTableView will be awfully slow with 30K rows * 150 columns, whatever you do.

    However --- regardless of reimplementing with a custom structure --- you must ask yourself why you would ever want to present a user with anywhere near that number of rows. There is no point/justification in giving a user 30,000 rows to scroll around. And that is apart from the fact that the memory footprint will be excessive.

    For that order of rows, you will want to implement some sort of "paging" mechanism, so the grid only gets filled with, say, 1,000 rows maximum at any time. Have a look at either MySQL Workbench or Microsoft SQL Server Management Studio. There is the potential there for a huge number of rows, obviously. Both of these offer a right-click for viewing your table which limits the rows fetched to 1,000.

  • Thanks everyone for answer.
    I am end up with write my own models, the load time reduce to 3s for 30k row and 150 col each.