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. Why my QAbstractTableModel table is slower than QStandardItemModel table?
Forum Updated to NodeBB v4.3 + New Features

Why my QAbstractTableModel table is slower than QStandardItemModel table?

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 2.8k 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.
  • J Offline
    J Offline
    justDance
    wrote on last edited by
    #1

    The table was using QStandardItemModel before, after I learned that QStandardItemModel is always slower than loading a custom model due to the creation of each individual QStandardItem based on book <<Advanced Qt Programming>> chapter 3.

    So I modified the table to QAbstractTableModel, of course implemented data(), setData(), headerData(), etc. those required functions.

    I can see the QAbstractTableModel table generation is about 100ms faster than QStandardItemModel, but I also notice scrolling up/down is much slower now. Is this normal?

    The data structure I have for QAbstractTableModel is QList<QList<QPair<QVariant, QVariant>>>, QPair<QVariant, QVariant> first QVariant is for display role, second is for sort role. Also the table row color can be different, so I have a QList<QList<QVariant>> data for ForegroundRole.

    The data structure for previous QStandardItemModel was QHash< QPair<int, int>, QPair<QVariant, QVariant> >, QPair<int, int> is cell index row and column, QPair<QVariant, QVariant> is first QVariant is for display role, second is for sort role(the same as QAbstractTableModel). It doesn't need data for ForegroundRole because I can set color for individual cell.

    Any ideas?

    Thanks,

    1 Reply Last reply
    0
    • J Offline
      J Offline
      justDance
      wrote on last edited by
      #2

      Did anyone try both QAbstractTableModel-based table and QStandardItemModel-based table, and find QAbstractTableModel-based table is slower in displaying?

      1 Reply Last reply
      0
      • C Offline
        C Offline
        ChrisW67
        wrote on last edited by
        #3

        I am not sure what you are expecting the world-at-large to contribute. Your code is slower, by whatever definition of slower, for reasons that can be seen by inspecting code only you have access to. You may be doing more work than you need, your data structure could be inefficient, you may not short circuit obvious null QVariant responses as soon as possible, your logic could just be plain broken...

        Generally the reason for using a custom model is to wrap data structures that are better suited to whatever else you need to do with them. "Better suited" might mean more frugal with memory, lazy-loaded (e.g. QSqlQueryModel), faster to write, faster to read, connected to a remote data source, easier to interface to other systems etc. There's no particular reason to expect a given custom model will display faster than a generic one.

        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