For a discussion on the differences between dynamic_cast and qobject_cast (and also the problems with dynamic_cast), see:
http://www.qtcentre.org/forum/f-qt-p...dget-5037.html
The trouble with dynamic_cast and templates boils down to the following issue:
* dynamic_cast (as implemented by gcc) uses a pointer to some type_info structure for testing types
* this structure exists multiple times if you instantiate a template in different translations units (ok, maybe only in different libs)
Therefore, using the 'same' templated type does not work as the dynamic_cast at one place uses a pointer to an equal but not the same type_info structure.
Fixes:
- maybe there is a common base type that you can factor out (i.e. templates are used in the subclasses, but you dynamic_cast to the base type)
- use qobject_cast instead (of course, only applicable with QObjects)
- use some other rtti mechanism and cast with static_cast
HTH
Christoph
Bookmarks