Lets consider this simple example:
Class Emitter: public QObject {
...
signal:
surfaceDestroyed(QObject*);
public:
void emittingMethod(QObject* surface) {
emit surfaceDestroyed(surface);
delete surface;
}
}
I have a queued connection for this case
connect(emitterObject, SIGNAL(surfaceDestroyed(QObject*), receiverObject,
SLOT(onSurfaceDestroyed(QObject*)), Qt::QueuedConnection);
In onSurfaceDestroyed method the received QObject is dereferenced and used
So the question is how safe this code is? I've read pretty much info on that on QT site and here, but I still don't have a clear understanding of the problem.
In my opinion this code is not safe, as a signal can be sent, then surface destroyed, than when an event comes for receiverObject once the event loop is processed and receiver object accesses released memory, thus SIGSEGV
This is a simplified example of real code, so it's hard to track if crashes can happen because of that.