PDA

View Full Version : dynamic_cast on class inherit from QGraphicsItem



Rogagol
4th February 2016, 20:03
Hello Guys, first i want sorry for my english ;)
I create class "Item", and that class inherit from QGraphicsItem.
I use scene()->collidingItems(this) to detect collisions, i want to know what objects colide, and use metod frome that object. So i do something like this:

QList<QGraphicsItem *> list;
list = scene()->collidingItems(this);

And now (please help me) how can I use metod from Item class, when list is QGraphiscItem? I try to use dynamic_cast, but i always get error "C2680: 'Item' : invalid target type for dynamic_cast target type must be a pointer or reference to a defined class" , maybe I do all wrong...
I hope that You understand me ;)

ChrisW67
4th February 2016, 20:23
You might be missing the "*" in the cast type.
Is it complaining on this?


Item *i = dynamic_cast<Item*>(list.at(0));
if (i) {
// you have a pointer to an Item
}

Rogagol
4th February 2016, 22:32
Now it works!
I was sure, that i tried with "*" ;)
Thx for qiuck reply.