Search code examples
c++qtvectorqstackedwidget

Accessing a widget within a QStackWidget


I'm creating dynamic widgets using the following code:

//class constructor
counter = 0; //int

//class method
vec_txt.push_back(new QTextBrowser()); //vector
ui->stackedWidget->addWidget(vec_txt[counter]);
counter++;

Now, I want to save the text in a file, but I don't know how to access the QTextBrowser object that is in the QStackWidget stackedWidget.

Is it even possible?


Solution

  • Yes, it is possible, just retrieve the widget at the desired index with this method :

    QTextBrowser* textBrowser = qobject_cast<QTextBrowser*>(stackedWidget->widget(index));