How can i get pointer on the widget of current tab in QTabWidget?
-
"QTabWidget::currentWidget()":http://doc.qt.nokia.com/latest/qtabwidget.html#currentWidget
-
"Wow do you read the doc??..":http://doc.qt.nokia.com/4.7-snapshot/qtabwidget.html#currentWidget
-
I read it before i asked, but on the this code
@ tabWidget->addTab(new QPlainTextEdit, "New tab");
QPlainTextEdit * p = qobject_cast<QPlainTextEdit *>(tabWidget->currentWidget());
p->setPlainText("dsg");@
Compiler get me a error, and thats why i asked you about it -
A bit hard to see what's wrong from just those four lines of code.
I assume qssTextEdit is a QPlainTextEdit subclass?
And that you haven't added any other tabs?
You could always check what tabWidget->currentWidget() actually returns, using a debugger or some form of debug output, e.g. by printing what tabWidget->currentWidget()->metaObject()->className() returns. -
To read the text associated with a tab's QTextEdit widget ( tab at index x) , I did this
@ tabWidget->addTab(new QTextEdit ,"New tab");
QTextEdit* t= qobject_cast<QTextEdit*>(tabWidget->widget(x));
qDebug() << t->toPlainText();
@Just in case someone still needed it.
-
Hi.. Ruzik
once try this code..
QTabWidget *wd;
tabWidget->addTab(new QTextEdit ,"New tab");QList<QTextEdit * > widgets = wd->findChildren<QTextEdit* >();
.....widgets.at(2) or widgets.at(index)