I'm looking for a solution to schedule the deletion of an object across threads. The docs about how deleteLater
behave are not entirely clear. Can I call this function in a thread which is not the object's owner?
For example, Object X is owned by Thread A, and in Thread B I would like to have Object X deleted. As the object may be inside event processing at the moment (in Thread A) I can't safely delete it until it gets back to the message loop. If I call deleteLater
from Thread B however the docs seem to indicate it will delete as soon as Thread B gets back to the message loop.
Currently I take the approach of having a signal emitted in Thread A which is attached to a slot which calls deleteLater
. I'm wondering if there is perhaps an easier way to do this -- if indeed I can just call deleteLater
from any thread.