PDA

View Full Version : graphics scene



dognzhe
3rd June 2009, 02:45
why i can not call add item from other thread?
it give warning:


QObject::startTimer: timers cannot be started from another thread
QObject::killTimer: timers cannot be stopped from another thread

aamer4yu
3rd June 2009, 06:18
How are you calling the timers ?
QGraphicsItem IS NOT inherited by QObject !

dognzhe
3rd June 2009, 08:23
How are you calling the timers ?
QGraphicsItem IS NOT inherited by QObject !

QObject::starttimer(40);

I am not create the timer inside of Item

any expert to explain why I get warning when I call addItem from other thread

shentian
3rd June 2009, 09:55
Qt Help tells us:


QObject and all of its subclasses are not thread-safe. This includes the entire event delivery system. It is important to keep in mind that the event loop may be delivering events to your QObject subclass while you are accessing the object from another thread.


In your case QGraphicsScene::addItem must be called from the main thread. This is necessary because addItem may post events (e.g. for updating the views). The warning appears because the current implementation of QGraphicsScene::addItem starts a timer to do some indexing.

In other words: Manipulate GUI objects only in the main thread.

Use a queued connection to notify you scene that it should add an item.