[Solved]How to close the application from child dialog box



  • Hello all,

    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
    @

    dialogCheckLicense.setModal(true);
    dialogCheckLicense.exec();
    

    @

    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:
    http://qt-project.org/forums/viewthread/10189

    Any suggestion appreciated (Would be better if code is included :) )

    Thanks
    Zain



  • 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

    dialogCheckLicense.setModal(true);
    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.



  • Hello All,

    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.



  • Hi!

    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 :)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.