[Interest] QIcons and multithreading

Alan Ezust alan.ezust at gmail.com
Wed Apr 3 16:14:51 CEST 2013


On Wed, Apr 3, 2013 at 3:44 AM, Sensei <senseiwa at gmail.com> wrote:

> 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));
>

no. You can't create widgets or QPixmap in other threads.


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

Correct.



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

Yes.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20130403/66958be7/attachment.html>


More information about the Interest mailing list