how to navigate with qwidget in qmainwindow
-
Hi everyone, can you help me?
My problem is i have one mainwindow with qcentralwidget, when user click on a button, then personnal widget is load and in the widget you can access to other widget.
To use that I use ```
this->setCentralWidget(widget_acc); // clicked for display param widget QObject::connect(widget_acc, SIGNAL(Display_widget_param()),this, SLOT(display_widget_param()),Qt::UniqueConnection);
with connect i handle display of other widget in slot :
void accueil::display_widget_param(){
this->param = new parametrage();
// clicked for back in index widget
QObject::connect(param, SIGNAL(Fermeture_parametrage()),this, SLOT(update_widget_accueil()),Qt::UniqueConnection);
QObject::connect(param, SIGNAL(Lancer_video()),this, SLOT(Lancer_video()),Qt::UniqueConnection);
this->setCentralWidget(param);
}if i delete this->param = new parametrage(); .
QObject::connect: No such signal QObject::Fermeture_parametrage()
QObject::connect: (sender name: 'parametrage')
QObject::connect: (receiver name: 'accueil')I have my first widget display, after i click button its ok, after I click back button for display first screen but connect dont worked, like if param sender had reset? I don't understand beacause it's run one times and my widget is initialize in my mainwindow so he can't reset no? I saw Qstatewidget for navigate it's better solution for me? and why connect work 1 times and after no? Thanks for you helping.
-
@kevin32 said:
hi
Its not 100% clear for me what you are trying :)
But
setCentralWidget is special
http://doc.qt.io/qt-5/qmainwindow.html#setCentralWidget
"Note: QMainWindow takes ownership of the widget pointer and deletes it at the appropriate time."This means that widget_acc will be deleted when you call
setCentralWidget(param); << u give it new, it deletes old.So if you try to go back to that Widget then it wont work.
If you need something like pages. So in mainwindow, you switch between
pages/screens, then QStackedWidget is super good for this. -
Thanks it's work, they are good example here http://stackoverflow.com/questions/31501462/why-doesnt-setcentralwidget-work .