[Qt-interest] Qt4.4.3 paintEvent thread-safe

Andreas Pakulat apaku at gmx.de
Mon Dec 22 14:12:09 CET 2008


On 22.12.08 14:43:42, Prasanta Sadhukhan wrote:
> which got solved when I introduced a mutex lock and unlock inside my 
> PaintEvent function, like this
> 
> void QtWindow::paintEvent(QPaintEvent *event)
> {
>  
>     AWT_QT_LOCK;
>     QPainter p(this);
>     QPoint pt(0,0);
>     p.drawImage(pt, *QtImageDescPool[0].offscrSurface);

I guess this array is shared by both threads, the Qt-painting thread and
the one that paints onto the offscreen image? If so, thats why you need the
lock, which probably causes the slowdown. There are only 2 solutions here:

a) provide a completely copy of the offscreen image to the qt-painting
thread instead of using a global array (for example by using a custom Qt
event that carries the QImage)
b) merge the code to have just 1 thread in the application.

Andreas

-- 
You possess a mind not merely twisted, but actually sprained.



More information about the Qt-interest-old mailing list