[Interest] QIcons and multithreading

Sensei senseiwa at gmail.com
Wed Apr 3 12:44:41 CEST 2013


Dear all,

I am using multiple threads in my application, and now I am wondering if 
I am doing something bad.

My application has a 'worker' thread that builds a tree with 
QTreeWidgetItems, setting QIcons for them.

Reading around, I found contradictory information about QPixmap (a 
warning that triggered my question here) and non-GUI threads.

Is this code safe to execute in a thread? The underlying graphic system 
*IS* initialized and running at the time the thread starts, this is 
something I can guarantee.


  item = new QTreeWidgetItem(QStringList(params));
  item->setIcon(0, QIcon(icons[i]));          // WARNING !!!
  item->setData(1, 0, QVariant(file));
  item->setData(2, 0, QVariant(idx));


The warning is "QPixmap: It is not safe to use pixmaps outside the GUI 
thread".

Also, besides QIcons, am I heading for disaster in creating widgets as I 
am doing in a separate threads?


Thanks & Cheers!



More information about the Interest mailing list