[Qt-interest] qobject_cast<> questions
Thiago Macieira
thiago.macieira at trolltech.com
Sat May 30 13:26:06 CEST 2009
Ross Bencina wrote:
>Hi everyone
>
>Does anyone know exactly when qobject_cast is needed and why (ie where
>dynamic_cast will crash)?
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.
>Is it only when using dynamically loaded
> plugins, or can it happen with any use of Qt as a shared library such
> as using the standard Qt DLLs and Frameworks from Qt Software (i'm on
> Win32 and OSX)?
See above. If you're using Windows, you should know how that platform's
ABI breaks the C++ standard. I don't have all the details either: I'm
afraid you'll have to learn by experience.
>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.
--
Thiago Macieira - thiago.macieira (AT) nokia.com
Senior Product Manager - Nokia, Qt Software
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/20090530/4c73ec3c/attachment.bin
More information about the Qt-interest-old
mailing list