Hi, so I'm dealing with a slight wall I met in my coding project.
I'm making a card game from a pre-written code using QFrame, and at this point I'm trying to implement the logic to send all cards from one deck widget to another deck widget after I send a signal for it.
Deck "deck_" sends signal to "pickedCards_" using signal, but "pickedCards_" has to send the cards to "deck_" without using signal.
What I initially tried was
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
Deck deck;
for (;;){
if (layout_->currentWidget() != nullptr)
{
layout_->currentWidget();
Card* card = static_cast<Card*>(layout_->currentWidget());
deck.receiveCard(card);
layout_->removeWidget(layout_->currentWidget());
layout_->setCurrentIndex(layout_->count()-1);
card->setAttribute(Qt::WA_DeleteOnClose);
card->close();
}else{
return;
}
}
|
where "Deck" is the class that deck_ is an object of. The problem I have in this code, is that I'm creating a new Deck object and as it has not been initialized in my mainWindow, it's not being drawn at all. At least, that's what I Think is the problem. The cards are properly being removed from the pickedCards_, and they do end up somewhere, but they're not drawn which leads me to believe that they're simply in a new Deck object that is not being drawn.
I read the documentation a bit and found out that
QObject::sender(); returns a pointer to the sender of the signal, but trying to use this with
1 2 3
|
QObject* deck;
deck = QObject::sender();
deck->receiveCard(card);
|
does not work with the error code "request for member 'receiveCard' in 'deck', which is a pointer type 'QObject*' ".
So I'm basically asking how I could securely send the card widgets back to the original deck_ object.
I also tried adding a function to my pickedCards class definition with
but it would not compile and instead complained about Deck not being defined (even though it's included in the .hh).