Qt Dynamic Cast Issues
Writing this little memo entry highlights my need for some sort of tagging system… I’m writing this in hopes of people with this unique annoyance to be transfered here via the google bot….
Ok. So your coding with QT 4 and using dynamic_cast for your implementations of Qt’s widgets… There’s a very good reason for you not to be doing this… There seem to be some unique issues, and besides — QT has it’s own method of casting which does not require RTTI. In the Porting to QT 4 document on Trolltechs website I noticed a little blurb about the special casts available to you in QT. You’re probably thinking “Yea I know about the qobject_cast” from the QObject documentation on QT’s website. Hold on, my friend! QT has more than just one weird cast, there’s:
- T *qobject_cast
(QObject *) - T qgraphicsitem_cast
(QGraphicsItem *) - T qstyleoption_cast
(QStyleOption *) - T qvariant_cast
(const QVariant &) - T qdbus_cast(const QDBusArgument &)
The one that interested me was qgraphicsitem_cast which is needed because QGraphicsItem does not inherit (indirectly or directly) from QObject. Oh yes, and to add to QT’s idiosyncrasies with casting it seems that if (QGraphicsItem*)->isVisible() returns false (the object is invisible), the cast fails for your subclasses… this might just be related to QT 4.3 though. Alright I’m done with my first geek sarcastic post. Hurrah!