Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
QGraphicsScene removeItem() - Find caller?
Chris3606 last edited by
I have a question about how to go about finding the caller of a function using Qt. I have an class instance that I wish to add to/remove from a QGraphicsScene, but I do NOT want to have this class inherit from QGraphicsItem or a derivation as you normally would. Instead, I wish to use a compositional structure, where this class whose instances I wish to add/remove has a member pointer to a QGraphicsItem derivation. I have also subclassed QGraphicsScene, and added a couple functions, addObject and removeObject. These do the same thing as addItem and removeItem, except they take in an instance of my class, and make sure to add/remove the QGraphicsItem component of the object passed in. The issue is that addItem automatically takes ownership of the item it adds, and removeItem automatically passes ownership of the item it removes to the caller. For this to work, I would like to replicate this ownership transferring functionality in my faddObject and removeObject functions, except it will transfer ownership of the object it takes in, not of the QGraphicsItem component. removeObject is my problem -- in a situation such as this, (how) can I figure out what the caller of a function is (and thus what object to pass ownership of the object I'm removing to)? I can post sample code if necessary, though it will be a bit lengthy.
Thanks in advance!
A quick idea would be to keep a hash of your objects with the QGraphicsItem as a key so you can easily retrieve which is the original owner.
Hope it helps