View Full Version : scene->addItem() moans about QTimer ???

10th December 2010, 11:25
I want to move an QGraphicsItem gi in a scene being displayed. I use

gi->setPos(x, y);

At that point I get a warning

QObject::startTimer: QTimer can only be used with threads started with QThread

and the view doesn't change. The warning totally foxes me. I have several threads in my program but gdb confirms all the basic GUI thread is active at this point. I don't want a timer, I want the view updated.

What is going on?

At first I had no removeItem addItem calls but that was gave the same warning.

Thanks for any suggestions,

10th December 2010, 11:29
Use a tracer or debugger to step trough the code.
I don't think it is possible to tell where the error is with the information you have given.

By the way, why do you remove an object from the scene in order to move its position?

10th December 2010, 14:58
Thanks. Will do some more debugging.

Remove/add back only to see whether that made a difference. It didn't.


14th December 2010, 17:20
Problem appears similar to what happens after calling update() from inside a paintEvent, against which the docs explicitly warn.

I am calling update() from inside a mousePressEvent() and can't do much else because it is the mouse press that should triggers moving a QGraphicsRectItem to that position. The rect->setPos(x,y) causes the QTimer warning.

After that a call view->update() does trigger a paintEvent but the rect does not get drawn at all.
It is almost as if the view does not notice the scene change and hence skips repainting.

Is this related to the new GraphicsItemFlags introduced in Qt 4.6. Before that things were working fine.

I am still puzzled.

15th December 2010, 01:33
You rarely need to call update() manually. If you just change the position of the item, update() is not required, setPos() will suffice. Just make sure it is all done from the GUI thread.

17th December 2010, 15:02
You put your finger on the sore spot: new scene in non-GUI thread. The docs warned me, you warned me but I did.