Is it safe to delete an object that is in a thread other than the current thread? For example:
MyObject *m = new MyObject();
// connect signal/slots, etc.
m->moveToThread(otherThread);
// much later in same thread:
delete m;
MyObject *m = new MyObject();
// connect signal/slots, etc.
m->moveToThread(otherThread);
// much later in same thread:
delete m;
To copy to clipboard, switch view to plain text mode
The question is: Does the "otherThread" know the object is deleted? If not, this could this cause a problem with event handling in otherThread. This would not seem to be solved by "deleteLater" because there are two different threads of execution. Is it necessary to have a "selfDestruct()" method on the "MyObject" which calls deleteLater? If the thread uses a QPointer or QSharedPointer internally this would probably be OK.
Bookmarks