[Interest] QIcons and multithreading

Alan Ezust alan.ezust at gmail.com
Thu Apr 4 18:45:46 CEST 2013


The reason, simply, is that the graphics memory and the objects that reside
in it are not thread-safe, and to make them thread-safe would cause a great
performance impact, so Qt doesn't try.
You can read more about this in the documentation, but in general, we use
QImage instead of QIcon in other threads, and we avoid creating or
accessing any QWidget from other threads, and instead communicate via
signals and slots to those objects from other threads. More is written
about it in the documentation:

http://qt-project.org/doc/qt-4.8/threads-modules.html

You can also read more about it in my chapter on "thread safety and
QObjects"

http://www.ics.com/designpatterns - login or register first then go to:
http://www.ics.com/files/designpatterns/book/threadsafety.html


On Thu, Apr 4, 2013 at 6:06 AM, Sensei <senseiwa at gmail.com> wrote:

> On 4/3/13 4:14 PM, Alan Ezust wrote:
>
>  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.
>>
>>
> Might I ask why is this?
>
> I don't start un-parented threads, my threads are always parent of my main
> window... not that this could somehow ameliorate the fact that I need
> refactoring. :)
>
> Thanks!
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20130404/ba009089/attachment.html>


More information about the Interest mailing list