QStackwidget Multiple pages Issue[SOLVED]
-
@marlenet15
ok.so you had a bug. i guess.
try this sample
https://www.dropbox.com/s/xuhzip7p52g4guk/sevenstacked.zip?dl=0
it can go back and forth. -
@mrjj I tried running it but nothing happens. The option to build is grayed out.
and also all the pages that I am adding onto the stackwidget are classes I created so I am not sure it that also created an issue when I tried doing it through .ui -
oh, go to Projects (left side icons) and adjust build path to
somewhere that exists or set it if none.Well the stacked controls QWidgets so its ok its your own I think.
-
@mrjj It tells me that 'File 'sevenstacked.pro' has modification time 2.9e+0.4 s in the future' and it just hangs
-
@marlenet15
OK?
Pretty strange.just delete it and make a new .pro file and put this in it
just a default one.#------------------------------------------------- # # Project created by QtCreator 2015-10-18T21:53:24 # #------------------------------------------------- QT += core gui greaterThan(QT_MAJOR_VERSION, 4): QT += widgets TARGET = sevenstacked TEMPLATE = app SOURCES += main.cpp\ mainwindow.cpp HEADERS += mainwindow.h FORMS += mainwindow.ui
-
@mrjj haha it gave me like 27 errors
-
@marlenet15
Ehh. ok.
Not sure what is going on.Make new default project and then copy mainwindow.cpp/h and mainwindow.ui
to it ?Anyway, was just a stacked widget with 10 pages and 2 buttons to go forth and back between the pages.
void MainWindow::on_pushButton_11_released() { int cur = ui->stackedWidget->currentIndex() + 1; ui->stackedWidget->setCurrentIndex(cur); ui->label->setText( QString::number(cur) ); } void MainWindow::on_pushButton_12_released() { int cur = ui->stackedWidget->currentIndex() - 1; ui->stackedWidget->setCurrentIndex(cur); ui->label->setText( QString::number(cur) ); }
-
@mrjj Ok so yes it does work that way. Do you have any idea why wouldn't work through the code I wrote?
-
@marlenet15
:) super
Well, I cant see how you create _page1 - _page7
you must have XX * _page1 = new XX; somewhere.
and it might crash if you use setCurrentWidget for deallocated
object or something like that.Also using setCurrentWidget, that widget must already be inserted into stacked.
Most of the time I just insert pages in UI as it is far easier.
You can even add dynamic also, if needed. -
@mrjj wouldn't it be page7 that could be deallocated? I have been looking at my code like 50 times and I still can't find the error. I set the pages on the UI and page7 still doesn't work :(
-
@marlenet15 Ok So I commented out 90% of the code and page7 works! So now I have to uncomment section by section to figure out what is making page 7 crash.
-
well its hard to guess when I cant see all code.
Do you do
QWidget *page7 = new QWidget()
when you create them ?
or now you insert them into the stacked in the UI ? -
@mrjj I inserted it now on the UI. I figured it out! I had another class where I had an array of QStrings which contains the titles for each page. I had an array of size 6 because I had only focused on the 6 pages I created. However, when I created the 7th page it would crash because the index 6 didn't exist since the array goes from 0-5. Thank you so much for your help!!!
-
@marlenet15
oh good found :)
Nasty one.