[Qt-interest] Guarded pointer safety

Arnold Krille arnold at arnoldarts.de
Fri Aug 14 22:48:04 CEST 2009


On Friday 14 August 2009 22:01:29 Imre Péntek wrote:
> 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.

If your app is single-thread only, there are no signals in the queue, because 
then all signals are direct connections.
But: There might still be events in the queue. I believe Qt uses autoguarded 
pointers in the event loops queue. But to be on the save side, delete your 
objects with deleteLater() so they get deleted via an event that is queue 
after all the events currently queued for your object.
That also works on multi-threaded apps where signals become events when 
crossing threads.

Have fun,

Arnold
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090814/e7510c61/attachment.bin 


More information about the Qt-interest-old mailing list