I am looking for a good/elegant way of making two different objects aware of eachother. Here is what I want to accomplish:
I have a QGraphicsScene that can contain any number of QGraphicsItems, and a QTreeView that lists the names of the QGraphicsItems within the scene in Z order (similar to photoshop's layers box)

I would like to be able to select an item in the scene and have the corresponding line be selected in the layers view, and vice versa.

Right now I have a semi-working solution using setData() to store a pointer to the other item. So the QGraphicsItem stores a pointer to the QStandardItem and vice versa. Here is an abstract of the code:

Qt Code:
  1. QStandardItem *standardItem = new QStandardItem();
  2.  
  3. QVariant graphicsItemVariant = QVariant::fromValue(graphicsItem);
  4. QVariant standardItemVariant = QVariant::fromValue(standardItem);
  5.  
  6. int key = 0;
  7.  
  8. graphicsItem->setData(key, standardItemVariant);
  9. standardItem->setData(graphicsItemVariant);
  10.  
  11. standardItem->data().value<QGraphicsPixmapItem*>(); //pointer to the graphics item
  12. graphicsItem->data(key).value<QStandardItem *>(); //pointer to the standard item
To copy to clipboard, switch view to plain text mode 

This seems to work fine when implementing the proper signals & slots, etc.
Except... When I use the above method, my program crashes when I go to internally drag & drop an item within the QTreeView. I've narrowed it down to actually setting the data on the QStandardItem. If I comment out line 10 above, the drag&drop behaviour is as expected (but obviously unable to select the corresponding QGraphicsItem within the scene)

Does anyone have any suggestions for the way I have done it or perhaps a better way to accomplish what I am trying to do? Thanks in advance!