I have a class inherits QGraphicsRectItem with type function
int RectItem::type() const
{
return UserType + 1;
}
int RectItem::type() const
{
return UserType + 1;
}
To copy to clipboard, switch view to plain text mode
But when I try to coverting a QGraphicsItem pointer to RectItem pointer, the qgraphicsitem_cast returns null.
QList<QGraphicsItem *> items = scene()->selectedItems();
for(int i=0; i<items.size(); i++){
if(items[i]->type() == UserType + 1)
RectItem*rectItem = qgraphicsitem_cast<RectItem*>(items[i]);
QList<QGraphicsItem *> items = scene()->selectedItems();
for(int i=0; i<items.size(); i++){
if(items[i]->type() == UserType + 1)
RectItem*rectItem = qgraphicsitem_cast<RectItem*>(items[i]);
To copy to clipboard, switch view to plain text mode
Here rectItem is null. However if I change the cast to dynamic_cast, the convertion will be successful.
QList<QGraphicsItem *> items = scene()->selectedItems();
for(int i=0; i<items.size(); i++){
if(items[i]->type() == UserType + 1){
RectItem*rectItem = dynamic_cast<RectItem*>(items[i]);
QList<QGraphicsItem *> items = scene()->selectedItems();
for(int i=0; i<items.size(); i++){
if(items[i]->type() == UserType + 1){
RectItem*rectItem = dynamic_cast<RectItem*>(items[i]);
To copy to clipboard, switch view to plain text mode
Here rectItem is the real RectItem selected.
Anyone knows why qgraphicsitem_cast is not working?
Thanks in advance.
Bookmarks