What is the proper way to update lots of QStandardItem?



  • 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?


  • Moderators

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


  • Qt Champions 2017

    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 ?



  • 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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.