Solved Close QDialog From Mainwindow
-
Hi All
I have a mainwindow application and I have created a Qdialog .Now I want to close the dialog from my mainwindow under these conditions1.If I click a close dialog button the dialog should close .
2.If I click mainwindow close button the dialog should close.
3.I don't if this is possible In case the application is closed through taskmanager the dialog should get closed.Here is my dialog invoking code
//your code here NewDialog *dialog = new NewDialog(); dialog->show();
Any solution is appreciated.
Thanks
Shiv -
@Shiv
1. You can use dialog->close();
2.remplementcloseEvent
doc.qt.io/qt-4.8/qwidget.html#closeEvent
3.this might help http://stackoverflow.com/questions/17061572/how-to-close-correctly-a-qt-program -
@Shiv said:
NewDialog *dialog = new NewDialog();
You should give it mainwindow as parent to make sure its
closed if mainwin is closed!NewDialog *dialog = new NewDialog(this); /// this being mainwindows
-
1.If I click a close dialog button the dialog should close .
default. if u made a true dialog. it does this already. -
2.If I click mainwindow close button the dialog should close.
you should move
NewDialog *dialog;
to mainwin .h as member and only do
dialog = new NewDialog();
Then in any mainwin function u can do
dialog->close(); to close it. -
3.I don't if this is possible In case the application is closed through taskmanager the dialog should get closed.
if u give it mainwin as parent , it will be closed too.
-
-