Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
[Solved]How to close the application from child dialog box
Please help me in this:
I have a main window and a child window dialog with it (not modal less).
I just opened the dialog from main constructor
I have a button on this dialog and want to close the application on this button click(from child window).
Please suggest how can I do it.
I found this with similar title but could not relate with my application:
Any suggestion appreciated (Would be better if code is included :) )
MuldeR last edited by
I think a more clean approach would be to just call done(x) with a special value in your Dialog.
Then, in your main Window you check the return code:
@#define SHUTDOWN 666
int retVal = dialogCheckLicense.exec();
if(retVal == SHUTDOWN) close(); //might do other clean-up work here...@
Other than that, you could still use QCoreApplication::exit(42) directly, I think.
MuldeR: Thanks for the reply.
Your solution worked :) ,
But it is showing a strange behavior, when I try to click on button close(I wrote this code on a button click in my checkLicenseDialog), It reappears again and need to click the close one more time.
So its working in two button clicks.
Can you please make me understand this behavior.
Well thanks again for the reply.
QMartin last edited by
To prevent that behaviour just connect your dialog button to qApp->quit(). For example:
@connect(yourDialogButton, SIGNAL(clicked()), qApp, quit())@
That should work.
Hello All Thanks for replies,
I got solution for it.
I used MyDialog.show() instead of MyDialog.exec();//it worked
Thanks once again :)