Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. speed up QTableview with large data
Forum Updated to NodeBB v4.3 + New Features

speed up QTableview with large data

Scheduled Pinned Locked Moved Solved General and Desktop
qtableviewqtableviespeed
5 Posts 4 Posters 9.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • O Offline
    O Offline
    oxycoder
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      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.

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      3
      • mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #3

        hi
        as already suggested a custom model might be the cure
        This talks about huge datasets
        http://doc.qt.io/qt-5/qtwidgets-itemviews-fetchmore-example.html

        1 Reply Last reply
        2
        • JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          @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.

          1 Reply Last reply
          2
          • O Offline
            O Offline
            oxycoder
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved