[Qt-interest] qobject_cast<> questions
Ross Bencina
rossb-lists at audiomulch.com
Sun May 31 09:05:44 CEST 2009
Hello Thiago
> dynamic_cast should never crash. But it may fail to work if you are trying
> to cast across DLL boundaries, depending on how the class was declared.
> It's a problem caused by the platform ABI's deviating from the C++
> standard mandated behaviour: it's the case on Windows as well as on
> platforms with hidden visibility.
Thanks for replying. I have been (apparently successfully) using
dynamic_cast to downcast QWidget ptrs on Windows for 2 years (Qt in DLLs,
all subclasses in App) so the actual behavior must be more subtle than you
imply.
Good to know that it shoudln't crash though... it turned out in this
instance I was passing a ptr to a freed object to dynamic_cast<>.
>>Also, can I rely on qobject_cast<> to work with null pointers? (ie to
>> return null if it is passed null?)
>
>The source code for Qt is available and writing a test for that is a
>couple of seconds.
Testing the actual behavior tells me nothing about the specified, expected
or required behavior. I hope that you guys do more than "check the source
code" to determine how such fundamental mechanisms as a type safe dynamic
cast are supposed to behave.
I'll file a documentation bug.
Thanks!
Ross.
More information about the Qt-interest-old
mailing list