PDA

View Full Version : qobject_cast vs dynamic_cast



mike_c
19th April 2010, 05:43
Hi,
Does anyone have an idea of the performance difference between a qobject_cast and a dynamic_cast? My understanding of dynamic_cast is that it's slow, and that the amount of time taken depends on the complexity of your object heirarchy, and whether you're upcasting, downcasting etc..
How does this compare with qobject_cast? Also i see that it doesn't require RTTI, so does Qt just emulate RTTI in its meta-object system?

Thanks,
mike

asvil
19th April 2010, 07:51
If you import c++ class from dynamic link library dynamic_cast not worked. I have not had time to try qobject_cast, but think that it worked.

mike_c
19th April 2010, 08:18
thanks, however i'm particularly interested in the performance difference (rather than the 'features' of one cast vs another).
and also, how does a qobject_cast resolve internally without RTTI?

faldzip
19th April 2010, 09:05
qobject_cast is generally faster and it uses Qt's meta object system.

wysota
19th April 2010, 09:58
and also, how does a qobject_cast resolve internally without RTTI?

So you are into features after all ;)

qobject_cast speed will also depend on the inheritance tree complexity but it only checks QObject inheritance so that's a "straight line" instead of a tree.

asvil
19th April 2010, 19:51
qobject_cast also casts Q_INTERFACES branch.