[Qt-interest] destroyed() signal and sender()

Thiago Macieira thiago.macieira at trolltech.com
Tue Dec 2 15:00:34 CET 2008


On Tuesday 02 December 2008 12:21:03 Anthony Serdyukov wrote:
> Some inherits QObject of course. But qobject_cast returns NULL, as
> dynamic_cast does too.
> Why so?

That happens because the destroyed() signal is emitted in QObject's 
destructor. As C++ goes, by the time the QObject destructor is run, the 
destructors for the more-specialised classes have already run and finished. 
That means your object is *really* a QObject at that point.

So qobject_cast is right when it returns 0: the cast did fail.

>Though static_cast works well, but it's not safe enough.

It's not a question of safety here: it's actually wrong. The object is no 
longer your type.

-- 
Thiago Macieira - thiago.macieira (AT) nokia.com
  Senior Software Engineer - Nokia, Qt Software
  Qt Software is hiring - ask me
      Sandakerveien 116, NO-0402 Oslo, Norway
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20081202/b020f9bc/attachment.bin 


More information about the Qt-interest-old mailing list