Accessing attributes of Widgets
-
In the mainwindow.iu I have added, to the MainWindow, centralWidget a stackedWidget with multiple pages. There is also a pushbutton in the centralWidget. I have set the slot of the pushbutton which created an empty function in mainwindow.cpp. Now, I have to write the code to make each press of the button step forward through the pages of the stackedWidget. This requires that I get the current page or index of stackedWidget. Then I need to increment it and use the setCurrentIndex attribute.
I cannot seem to do this! Can someone please give me the exact syntax for accessing these attributes?
int currentPage = Ui_MainWindow::stackedWidget->currentIndex();
seems to be the closest I can get.
-
int currentPage = ui->stackedWidget->currentIndex();
In your MainWindow.h, you have
Ui::MainWindow *ui;
as a private member variable. So you would useui->
to access ui's members. -
I get expected primary-expression before '->' token pointing at Ui->
-
Well, DUH! You did, after all show it as lower case.
Thanks a bunch! -
It's good to know I won't make that mistake again!