Weird error with QGraphicsItem sent from one thread to another.
Hello everyone, I'm facing a strange error.
I have a processing thread that emit a few signal with QGraphicsItem* in parameters.
Those signals are connected to the main thread which then add them to a QGraphicsViews.
It works pretty well, until today. In addition to the ellipses and line I decided to add a QGraphicsTextItem*
It still work, until the application loses focus. At this very specific moment, I get this error:
Why does it crash with text items only? And why when the application loses focus?
You can't do that. QGraphicsItems are GUI objects, and can only be manipulated from the GUI thread. What you are trying to do is not supported, and can indeed lead to weird crashes and other undefined behaviour.
But the thread is only responsible for creating the object. All the display is done in the main thread.
AFAIK, that doesn't matter.
Each QObject derived class belongs to the thread, that creates it (Thread affinity). So creating UI objects in a non UI thread is a no go.
But QGraphicsItem does not derive from QObject.
But it is a UI object, and it could be that it stores some data...
Maybe some special cases for the text items...