Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Destruction in separate threads
KevinKnowles last edited by
Let's assume we have two threads (thread1 and thread2), each running their own event loop hosting a single QObject (obj1 and obj2). The signals of the two QObjects are connected to slots on the alternate object, and aside from this signal-slot communication, the two objects do not access each other directly.
Is it safe if obj2 is destroyed, without disconnecting it from obj1 first, while obj1 continues to execute in its own thread?
Is there any way that obj1 might hit some race condition where it sends a signal to obj2 before obj2 can disconnect itself?
Keep in mind: In my hypothetical case, the thread2 message loop is being shut down immediately following the obj2 destruction, so any lingering obj2 messages shouldn't be a problem (otherwise, I would use deleteLater()).
If a deleteLater signal is put into the message loop, but the message loop is then immediately exit()ed, is the object ever deleted? If it isn't, is this a bug? It seems that deleteLater's should always be processed, even if a thread is closing.