Hi,

I have a QGraphicsTextItem custom object that contains QGraphicsRectItem(s). In my scene's mouseReleaseEvent, I have code to look through the QList<QGraphicsItem *> and only act when the item is of a specific type, Port::Type which is enum { Type = UserType + 16 };

I notice that my QList<QGraphicsItem *> also contains the QGraphicsItemPrivate d_ptr when I select on the QGraphicsTextItem custom object itself, resulting in a crash on the "int aType = anItem->type();" line

My questions are:
1) why the d_ptr is returned in my items() call
2) how am I going to modify my following code to just look for a specific type, Port *, but ignore everything else in the items() call. Thanks

Qt Code:
  1. Port *oport = 0;
  2. while (!startItems.isEmpty()) {
  3. QGraphicsItem* anItem = startItems.takeFirst();
  4. if (anItem) {
  5. int aType = anItem->type();
  6. if (aType == Port::Type) {
  7. oport = qgraphicsitem_cast<Port *>(anItem);
  8. break;
  9. }
  10. }
  11. }
  12.  
  13. where Port is a QGraphicsRectItem
To copy to clipboard, switch view to plain text mode