I have implemented the type() method for all of my derived classes so that qgraphicsitem_cast would work. I just tested it out and apparently it will not work unless the value returned is an enum of the class. Returning an enum that isn't part of the class fails every time. I'm showing this here incase someone else ruins into the same pitfall, as qgraphicsitem_cast doesn't explain this in the documentation and the only place to find the way it will work is in the examples:
//ENUMFROMINCLUDEDHEADER is greater than UserType //will not work as a one liner :( virtual int type() const { return ENUMFROMINCLUDEDHEADER; } //will work ONLY if it is named Type enum { Type = ENUMFROMINCLUDEDHEADER }; virtual int type() const { return Type; } - Swyped from my droid. On May 23, 2013 12:29 PM, "Constantin Makshin" <cmaks...@gmail.com> wrote: Yes, qgraphicsitem_cast isn't as powerful as dynamic_cast, but this simplicity also makes it faster. Anyway, Jonathan asked about casting C++ objects and now has several methods to choose from. :-) On May 23, 2013 9:17 PM, "Jan Kundrát" <j...@flaska.net> wrote: > > On Thursday, 23 May 2013 19:04:... _______________________________________________ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest
_______________________________________________ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest