MainWindow of my Qt application has QTabWidget, where each tab is a QTableWidget. I need to get access to the selected cell of a current table (with currentRow()
and currentColumn()
). But when I'm taking pointer to the table with ui->tabWidget->currentWidget()
result is QWidget* so for it methods like currentRow()
don't exist.
Is there any way to determine that all pages of QTabWidget are members of QTableWidget class?
You can use qobject_cast
to check if an object of type QObject
is an object of type T
inherits from QObject
QWidget *widget = ui->tabWidget->currentWidget();
QTableWidget *tableWidget = qobject_cast<QTableWidget*>(widget);
if (tableWidget != 0)
{
/// Do work
}
By the way, you can get all QTableWidget
in you tab by
QList<QTableWidget *> allTables = ui->tabWidget->findChildren<QTableWidget *>();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.