[Interest] QIcons and multithreading
Sensei
senseiwa at gmail.com
Fri Apr 5 13:55:41 CEST 2013
On 4/5/13 1:38pm, Bo Thorsen wrote:
> Den 05-04-2013 13:09, Sensei skrev:
>> By the way, and just for a thorough exploration of my code, is
>> QTreeWidgetItem *without icons* safe to be constructed in a separate
>> thread?
>
> Looking at the source code, it might actually work. But you will be
> depending on the internal implementation of QIcon, so I wouldn't do that
> if I were you. And worse, it will be a maintenance nightmare, because
> you will have to rely on noone using the QIcon in the code later.
>
> Don't do it.
>
> Bo.
>
I understand. The trick I'd use is this:
- create items in thread, associating QStrings (via data())
- slot when finished in the main GUI thread
- for each item set a brand new icon via QIcon(data().toString())
(I use data to attach some information in a tree)
This is done repeatedly, since I'm using a timer to update the tree: in
the slot I clear and add new items in the QTreeWidget.
It's not that nightmare I hope! :)
More information about the Interest
mailing list