Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved]How to close the application from child dialog box

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

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 1.7k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Z Offline
    Z Offline
    Zain
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • M Offline
      M Offline
      MuldeR
      wrote on last edited by
      #2

      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.

      My OpenSource software at: http://muldersoft.com/

      Qt v4.8.6 MSVC 2013, static/shared: http://goo.gl/BXqhrS

      Go visit the coop: http://youtu.be/Jay...

      1 Reply Last reply
      0
      • Z Offline
        Z Offline
        Zain
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • Q Offline
          Q Offline
          QMartin
          wrote on last edited by
          #4

          Hi!

          To prevent that behaviour just connect your dialog button to qApp->quit(). For example:

          @connect(yourDialogButton, SIGNAL(clicked()), qApp, quit())@

          That should work.

          1 Reply Last reply
          0
          • Z Offline
            Z Offline
            Zain
            wrote on last edited by
            #5

            Hello All Thanks for replies,

            I got solution for it.
            I used MyDialog.show() instead of MyDialog.exec();//it worked

            Thanks once again :)

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved