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. Check button press of QMessageBox
Forum Updated to NodeBB v4.3 + New Features

Check button press of QMessageBox

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 4 Posters 1.3k Views 1 Watching
  • 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.
  • H Offline
    H Offline
    hobbyProgrammer
    wrote on last edited by
    #1

    Is it possible to check if the button from the messagebox was pressed?

    QMessageBox::warning(this,
    tr("Some Header Text"),
    tr("Some Text"),
    QMessageBox::Save);

    I would like to check if the save button was pressed. The application exists on the normal use of QMessageBox as this closes the latest window.

    1 Reply Last reply
    0
    • Q Offline
      Q Offline
      qt.1234
      wrote on last edited by qt.1234
      #2

      Hi,

      you can try this:

      QMessageBox msgBox;
      
      int ret = msgBox.exec();
      
      switch (ret)
       {
        case QMessageBox::Save:
            std::cout << "save" << std::endl;
            break;
        default:
            break;
      }
      
      H 1 Reply Last reply
      1
      • Q qt.1234

        Hi,

        you can try this:

        QMessageBox msgBox;
        
        int ret = msgBox.exec();
        
        switch (ret)
         {
          case QMessageBox::Save:
              std::cout << "save" << std::endl;
              break;
          default:
              break;
        }
        
        H Offline
        H Offline
        hobbyProgrammer
        wrote on last edited by
        #3

        @qt-1234 Hi, but exec() is the thing that I was talking about that closes the latest opened window and that closes my app.

        JonBJ 1 Reply Last reply
        0
        • H hobbyProgrammer

          @qt-1234 Hi, but exec() is the thing that I was talking about that closes the latest opened window and that closes my app.

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #4

          @hobbyProgrammer

          The application exists [sic., should be exits] on the normal use of QMessageBox as this closes the latest window.
          closes the latest opened window and that closes my app

          You really cannot carry on with code like this. Running a QMessageBox and the user closing it should not close your application. You must stop and re-architect your code to deal with that first. Otherwise you won't be able to implement perfectly normal solutions like @qt-1234 has given.

          EDIT For that, go back to your original thread on this, https://forum.qt.io/topic/108636/qt-app-doesn-t-close-properly-still-visible-in-task-manager, I'm posting a brief reply there now

          1 Reply Last reply
          4
          • mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Hi
            Why should exec() close the app?

            You might run into this
            https://doc.qt.io/qt-5/qguiapplication.html#quitOnLastWindowClosed-prop

            this is true pr default so if it thinks you closed the last top window, it will
            quit the app.

            so for test, try setting it to false and see if it still closes whole app.

            It the norm to use exec() to show dialogs as to have them as modal so you really should find out why it closes the app if you use it.
            Bug or just the bool flag.

            JonBJ 1 Reply Last reply
            0
            • mrjjM mrjj

              Hi
              Why should exec() close the app?

              You might run into this
              https://doc.qt.io/qt-5/qguiapplication.html#quitOnLastWindowClosed-prop

              this is true pr default so if it thinks you closed the last top window, it will
              quit the app.

              so for test, try setting it to false and see if it still closes whole app.

              It the norm to use exec() to show dialogs as to have them as modal so you really should find out why it closes the app if you use it.
              Bug or just the bool flag.

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by
              #6

              @mrjj
              This issue is being covered in OP's other thread https://forum.qt.io/topic/108636/qt-app-doesn-t-close-properly-still-visible-in-task-manager. Trying not to get it (re-)discussed all over! :)

              mrjjM 1 Reply Last reply
              1
              • JonBJ JonB

                @mrjj
                This issue is being covered in OP's other thread https://forum.qt.io/topic/108636/qt-app-doesn-t-close-properly-still-visible-in-task-manager. Trying not to get it (re-)discussed all over! :)

                mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @JonB
                Ah, thx. so Poster knows about toplevel windows etc.
                No reason to get into that again then :)

                1 Reply Last reply
                1

                • Login

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