Delete a clicked object from the scene?
-
I want to come back to this, because I can't seem to get things together.
It seems to me that if I could get to return the object clicked in my scene (that being a card), I could finally move on. Documentation just confuse me further, even my own code has the same effect at the moment..
-
Hi,
Pseudo code:
@
MyClass::whereItNeedsToBeFunction(){
// Create the card
connect(card, SIGNAL(clicked()), this, SLOT(cardClicked());
}void MyClass::cardClicked()
{
CardClass *card = qobject_cast<CardClass *>(sender());
if (card) {
// do what you want with the card
}
}
@Hope it helps
-
Thank you again, SGaist! I'll work on this as soon as I get a chance. Before I start though, I'm using visual studio. Would "connect" be recognized?
EDIT
Or any other piece of this that's only a part of Qt environment?
-
Since you are already compiling a Qt project with VS, there should not be any problem
-
Hm, when I type 'connect' it's not in the pop-up list.
-
Your Card class is not a QObject ?
-
Only QGraphicsPixmapItem. I thought though that it derives from QObject
-
No they are not, for their original use case, deriving from QObject would not make sense. If you need signals and slots in a QGraphicsItem there's also QGraphicsObject to have a look at
-
Oh boy, wish I had known that before hand. Back to rewriting chunks of code
-
The documentation is your friend ;)
-
Hint taken :) At that point I didn't know what sort of functionality I was going to need, plus I was only starting out with Qt. Oh well, lesson learned :)