In my project, I have a function that recursively iterates over the model of a QTreeView
. At certain points, I append values to a QStringList
that is stored in each item's Qt::UserRole
.
Here's the issue... the recursive scanning does a ton of checking, reading from JSON file, importing icons from disk, etc etc HOWEVER, all of that is miles faster than simply appending 1 or 2 strings to the QStringList
for about 5% of the items in the model.
I did some basic profiling and found that if I comment out all calls to QStringList::append()
but LEAVE IN all the crazy JSON reading, icon setting, color changing, etc, it is 3 times faster than if I left them in. And it is noticeably slower... frustratingly slower.
So I decided to narrow it down to only 1 call to QStringList::append()
on about 5% of the items. Here is the example of code:
QStringList rightClickList = mainItem->data(Qt::UserRole+8).toStringList();
rightClickList.append("customName");//comment this out and it runs 3x faster
//than allllll the recursive scanning combined!
mainItem->setData(rightClickList, Qt::UserRole+8);
I would estimate about 5% of all the items in a given model have any QStringList
changes at all. The rest are left alone. Are QStringList
types really that slow? If so, what alternative would you recommend?
Thanks for your time!