[Qt-interest] Guarded pointer safety

Imre Péntek pentek.imre at gmail.com
Fri Aug 14 22:01:29 CEST 2009


Hello!

I've read the doc at http://doc.trolltech.com/qq/qq14-guardedpointers.html , 
and I am still wondering whether it is safe to use QPointer even in a single-
threaded QT application. At the time I delete the object, it might be a signal 
in the queue pending, with the appropriate slots using that exact object.

So, as I imagine the scenario:
1. for some reason there is two signals in the queue
2. the slot connected to the first one deletes that object, so the signal that 
would act upon the deletion would be served third
3. the slot connected to the second one uses that pointer: if(p) segfault.
4. if we wouldn't crashed already, that p would be set to zero here

So, what guarantees that a scenario like this can't happen? Is guarded pointer 
safe to use?
-- 
With Regards: Imre Péntek
E-Mail: pentek.imre at gmail.com





More information about the Qt-interest-old mailing list