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

Anthony Serdyukov uksus70 at gmail.com
Tue Dec 2 16:52:26 CET 2008


Thank you, Thiago, for the explanation. I thought this direction. So,
if one want to talk to some dying object, he should do it earlier.
Just as in our life...

2008/12/2, Thiago Macieira <thiago.macieira at trolltech.com>:
> 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
>


-- 
Regards,
Anthony



More information about the Qt-interest-old mailing list