Drawing from multiple threads in Qt

I am writing a program in Qt that starts 10 workflows that calculate the trajectory of an object in space. They should also draw the path of the object. I have a Body class that receives a QGraphicsEllipseItem, and it has a QPainterPath in it. The Modeling class takes a list of obstacles in the world, and the body imitates and works until the body collides with something. The simulation is performed in a separate thread (performed using moveToThread, and not by subclassing QThread). When the body collides, the simulation emits a signal saying that it is finished. When all the threads are finished, I would like to draw the paths (I do this by calling the method in "Body", which allows you to draw paths in the drawing method).

Unfortunately, I get ASSERT errors:

ASSERT: "!unindexedItems.contains(item)" in file graphicsview\qgraphicsscenebsptreeindex.cpp, line 364

They happen, it would seem, randomly. I tried different types of connections, with no result.
I start threads in a loop.
I am using Qt 5.0

+5
source share
2 answers

Generally speaking, with Qt, you cannot perform any GUI operations outside of the GUI thread (i.e. the thread executing QApplication :: exec (), which is usually the main () thread).

, , QGraphicsItems ( QGraphicsItems, QGraphicsScene), , , . , Qt GUI , QGraphicsItem , QGraphicsItems . QGraphicsItem ( ) , , , / (/ ).

, , , , , Qt GUI. , , Qt GUI ( QApplication:: postEvent()). GUI QGraphicsItems ..; "", .

, , GUI; .

+10

, Qt .

, , , , , . - , Model/View/Controller.

, QGraphicsItem/Objects. , , , .

+3

All Articles