Why do you think that the scene index returned in the QList is a constant that won't change? The scene could change the order of items in it based on the current stacking order of things in the scene, and the order can change as you add new items to the scene. And if you have QGraphicsLineItem, QGraphicsTextItem, and QGraphicsRectItem instances in the scene, all of these will have an index, too, and the index will depend on where they are in the hierarchy of scene objects.if (CORE::castPtrType<C2DM::LinkState>(m_pLinkStateLi stModel->getTitle(indexOfShape)))// getTitle is looking for the index clicked
The only way you can guarantee that you can look up something by an index number is if you assign the index number yourself. The easiest way to do this is to use the mechanism you are already using on your rect objects: use another setData() property to assign the index to your rects. If you are using the key "0" already, then use a different key (1) to assign an index when you create the rect. If you are only indexing the rects, then start at index 0 and increment as you add new rects.
If you ever delete a rect, then you will have to make sure that your model and your rects remain consistent - if you remove a rect with index 42, because you have removed the title with index 42, then you have to make sure that you either re-index everything from 42 up or access title <---> rect relationship in a way that is not affected by missing index numbers. Once again, an std:: map<> would work great for this.
Bookmarks