PDA

View Full Version : QGraphicsItem + Threads = Crash ?



medved6
5th December 2009, 10:20
Hi all.

I'm using QGraphicsItems in my scene. And from time to time I need to call QGraphicsItem->update() function.
I call update function from different threads ( one thread per item, and only this thread calls update for this item + application event thread ).

And form time to time (randomly) it crashes inside update() function ( voidQList<T>::append down to stack).

Even if I use common Mutex for all calls of update ( so I have 2 threads calling update(): item thread + application event thread )
I'm using QT 4.5.2 for Widows (VS 200.

Does anybidy know this issue ?
Thank you!

caduel
5th December 2009, 10:53
You may not use (or call methods of) QWidgets from any thread but the main thread. Calling update() on a QGraphicsItem in all probability leads to such a call.

Try sending your main thread a signal instead and have the main thread call update.

HTH

medved6
5th December 2009, 20:06
I thought that update just schedulel paint...
So are you saing that to repaint item i need to send signal to main thread and after that make main thread just schedul paint event? Is there any way to schedul paint event directly from my thread ?

Thank you for replay!

medved6
6th December 2009, 05:13
Thank you. It works now, I did as you said.