On Thursday, 23 May 2013 19:04:53 CEST, Constantin Makshin wrote:
> There's also qgraphicsitem_cast made specifically for casting to classes
> derived from QGraphicsItem.

It is also of very limited value in real world because it does not support 
inheritance -- it can only cast to the exact type of the item in question.

Suppose you have a hierarchy -- C derives from B which derives from A. A 
dynamic_cast of a C to all of B and A will succeed, but a qgraphicsitem_cast 
will return a null pointer when casting a C* into either B* or C*, only 
succeeding when casting to A*. Depending on what you're looking for, being able 
to fully utilize the inheritance tree might or might not be important for you.

(Actually, the bits above are a little bit simplified; the casting is performed 
based on the target class' Type member, so in cases where you e.g. derive from 
a QGraphicsItemText but forget to provide your own Type value, a cast to 
QGraphicsItemText will succeed. Of course, you cannot distinguish between a 
QGraphicsItemText and your own class via qgraphicsitem_cast in this situation.)

Cheers,
Jan

-- 
Trojitá, a fast Qt IMAP e-mail client -- http://trojita.flaska.net/
_______________________________________________
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest

Reply via email to