as the title says, i want to access the member variables of a class that inheritates of QWidget from a QGridLayout in a QMainWindow. I am able to access member functions of the QWidget class, but i cant reach the members of my "Player" class.
I am aware, that "->widget()" returns just a QWidget*. Is there another way to return the real class, which sits at this coordinates?
This question shows just to access functions of the QWidget but not of classes inheritated of QWidget.
Code of the QMainWindow class:
...
for(int row = 0; row < rowsCount; row++) {
for(int col = 0; col < colsCount; col++) {
QWidget *player = this->ui->gridLayout->itemAtPosition(row, col)->widget();
player->[HERE I WANT TO ACCESS THE PUBLIC MEMBER]
}
}
...
If I well understand you just have to dynamic cast your widget to a Player and check you really have a Player by security :
QWidget *widget = this->ui->gridLayout->itemAtPosition(row, col)->widget();
Player * player = dynamic_cast<Player *>(widget);
if (player != NULL) {
...
}