Reputation: 5090
I have a QTabWidget with 2 tabs and I promoted each to 2 custom widgets. Those widgets have functions "typeName()" and "baseName()", but I cannot access those functions with "QTabwidget->currentWidget()".
std::string type = ui->tabWidget->currentWidget()->typeName().toUtf8().constData();
std::string base = ui->tabWidget->currentWidget()->baseName().toUtf8().constData();
This throws me an error "it has no member named ..."
What am I doing wrong?
Upvotes: 1
Views: 828
Reputation: 3049
You need to make an explicit (down) cast to the particular type in the tab. The functions are not present in base class QWidget which is returned by currentWidget().
std::string type = dynamic_cast<CustomType*>(ui->tabWidget->currentWidget())->typeName().toUtf8().constData();
Upvotes: 2