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. What is the proper way to update lots of QStandardItem?
Forum Update on Monday, May 27th 2025

What is the proper way to update lots of QStandardItem?

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 4 Posters 651 Views
  • 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.
  • M Offline
    M Offline
    Mr Pang
    wrote on last edited by Mr Pang
    #1

    I have a QStandardItemModel and have a lot of items. The Items may changed their Text frequently.
    I use perf to find out the bottleneck of my task. And found that QStandardItem::row() cost above 80% cpu cycle. After add some workaround to skip the calling of QStandardItem::row(), I found QStandardItem::setText() cost above 80% cpu now.
    Both row() and setText() are finally calling QStandardItemPrivate::position(), which is the real expensive function.

    I can move row() to another thread, but is it safe to call setText() in another thread?

    jsulmJ 1 Reply Last reply
    0
    • M Mr Pang

      I have a QStandardItemModel and have a lot of items. The Items may changed their Text frequently.
      I use perf to find out the bottleneck of my task. And found that QStandardItem::row() cost above 80% cpu cycle. After add some workaround to skip the calling of QStandardItem::row(), I found QStandardItem::setText() cost above 80% cpu now.
      Both row() and setText() are finally calling QStandardItemPrivate::position(), which is the real expensive function.

      I can move row() to another thread, but is it safe to call setText() in another thread?

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Mr-Pang Moving setText() to another thread will not make it faster and modifying GUI related classes from other threads as GUI thread is not allowed. The question is: why do you need to modify so many items so often?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

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

        In addition what @jsulm said, from where the data is coming ? Is it user entering it or some back end process updates it ? What is the size of your model ? How many rows & cols ?

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

        1 Reply Last reply
        3
        • VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on last edited by
          #4

          One more question is it flat (i.e. is it a table or a tree)?
          QStandardItemModel is known to be not very efficient so you might find out subclassing your own model is the the way to go

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          1 Reply Last reply
          1

          • Login

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