You can use the widget function QTabWidget to get the widget with the specified tab index.
If QPlainTextEdit is the only widget on each tab page, then the returned widget will be like this. Otherwise, you need to get the children widget and find QPlainTextEdit in it.
QPlainTextEdit* pTextEdit = NULL; QWidget* pWidget= ui->tabWidget->widget(1); // for the second tab // You can use metaobject to get widget type or qobject_cast if (pWidget->metaObject()->className() == "QPlainTextEdit") pTextEdit = (QPlainTextEdit*)pWidget; else { QList<QPlainTextEdit *> allTextEdits = pWidget->findChildren<QPlainTextEdit *>(); if (allTextEdits.count() != 1) { qError() << "Error"; return; } pTextEdit = allTextEdits[0]; } // Do whatever you want with it... ptextEdit->setPlainText("Updated Plain Text Edit);
source share