5
votes

I think i'm having a fairly basic Qt problem, but i can't figure it out:

I have a QMainWindow which holds a QStackedWidget. All page widgets in there are seperate classes derived from QWidget.

So:

QMainWindow implements QStacked Window in one class. All other pages inside the stacked widget are added classes and all have there own .ui filled with buttons and lists trough the Designer.

For navigating to different pages, inside the Mainwindow i have access to: ui.stackedWidget->setCurrentIndex(2);

It seems i don't have access to ui.stackedWidget on another page inside the stacked widget? I have no access to the ui.stackedWidget because Ui is a private member in the mainwindow class. (auto generated by Qt - using VS addon for adding QT4 classes)

I would like to know, how can i jump to another page in the stacked widget, when clicking on a button that belongs to another page inside this widget?

Note:

All pages are added to the StackedWidget in mainWIndow's constructor:

ui.stackedWidget->addWidget(page1Widget);
ui.stackedWidget->addWidget(page2Widget);
// etc..

Example of a button click signal-slot inside page1Widget:

connect(ui.btnViewData, SIGNAL(clicked()), this, SLOT(viewData()));

::viewData() 
{   
   // navigate to another page here. 
   // note: ui.stackedWidget->setCurrentIndex(3); is not accessible here!
}
1

1 Answers

4
votes

I believe that putting your connect() and viewData() functions within your QMainWindow object will solve your problem, since the main window can have access to both the signals emited by the child widgets and the QStackedWidget items.

You might need to write a Ui getter for each of your page, and then do something like

connect(page1Widget->getUi().btnViewData, SIGNAL(clicked()), this, SLOT(viewData)));

hope it helps, cheers