khajvah
khajvah

Reputation: 5090

Accessing QTabWidget's widget

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

Answers (1)

user2672165
user2672165

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

Related Questions