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. Show messageBox when click exit button on titlebar.
Qt 6.11 is out! See what's new in the release blog

Show messageBox when click exit button on titlebar.

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 3 Posters 1.8k 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.
  • mangekoyuM Offline
    mangekoyuM Offline
    mangekoyu
    wrote on last edited by
    #1

    I want to show a MessageBox when User click to exit button on title bar for close application In my qdalog.

    When user click exit button messagebox should ask about quit and if user click yes, I will close my serial port and close Qdialog. How can I do this?

    JonBJ 1 Reply Last reply
    0
    • mangekoyuM mangekoyu

      I want to show a MessageBox when User click to exit button on title bar for close application In my qdalog.

      When user click exit button messagebox should ask about quit and if user click yes, I will close my serial port and close Qdialog. How can I do this?

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

      @mangekoyu
      You might want to close serial port from QCoreApplication::aboutToQuit(). But you can't show a dialog or ask from there.

      For the dialog you need to subclass QMainWindow (you should already be doing that) and override closeEvent. There you can show a dialog and only accept the close event if the user confirms. See e.g. show a dialog before closing the program in Qt.

      1 Reply Last reply
      1
      • mangekoyuM Offline
        mangekoyuM Offline
        mangekoyu
        wrote on last edited by mangekoyu
        #3

        @JonB

        Well, considering I open a qdialog via mainwindow. The application is running. I just want to close the dialog and when I press the button I want it to ask a question to close the dialog. how can I do that?

        JonBJ 1 Reply Last reply
        0
        • mangekoyuM mangekoyu

          @JonB

          Well, considering I open a qdialog via mainwindow. The application is running. I just want to close the dialog and when I press the button I want it to ask a question to close the dialog. how can I do that?

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

          @mangekoyu
          I answered just that above, and gave you a reference with suitable code. Unless you are asking a different question?

          1 Reply Last reply
          0
          • mangekoyuM Offline
            mangekoyuM Offline
            mangekoyu
            wrote on last edited by
            #5
            void productDetail::closeEvent1(QCloseEvent *event)  // show prompt when user wants to close app
            {
                event->ignore();
                if (QMessageBox::Yes == QMessageBox::question(this, "Close Confirmation", "Exit?", QMessageBox::Yes | QMessageBox::No))
                {
                    event->accept();
                }
            
            }
            

            I tried sth like this but message box does not shown.

            @JonB

            J.HilkJ JonBJ 2 Replies Last reply
            0
            • mangekoyuM mangekoyu
              void productDetail::closeEvent1(QCloseEvent *event)  // show prompt when user wants to close app
              {
                  event->ignore();
                  if (QMessageBox::Yes == QMessageBox::question(this, "Close Confirmation", "Exit?", QMessageBox::Yes | QMessageBox::No))
                  {
                      event->accept();
                  }
              
              }
              

              I tried sth like this but message box does not shown.

              @JonB

              J.HilkJ Offline
              J.HilkJ Offline
              J.Hilk
              Moderators
              wrote on last edited by
              #6

              @mangekoyu do you know how overriding works ?

              productDetail::closeEvent1(QCloseEvent *event) the base function most certainly does not have a 1 at the end of the function name.


              Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


              Q: What's that?
              A: It's blue light.
              Q: What does it do?
              A: It turns blue.

              1 Reply Last reply
              2
              • mangekoyuM mangekoyu
                void productDetail::closeEvent1(QCloseEvent *event)  // show prompt when user wants to close app
                {
                    event->ignore();
                    if (QMessageBox::Yes == QMessageBox::question(this, "Close Confirmation", "Exit?", QMessageBox::Yes | QMessageBox::No))
                    {
                        event->accept();
                    }
                
                }
                

                I tried sth like this but message box does not shown.

                @JonB

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

                @mangekoyu said in Show messageBox when click exit button on titlebar.:

                void productDetail::closeEvent1()

                Did the example put a 1 at the end of closeEvent? You cannot just type in something different from what an example shows and then say why does it not work.....

                I tried sth like this

                People can't help much if you say you have code "something like", how can we know what you actually have?

                Please think about phrasing questions and giving detail/proper code, people cannot guess what you might be doing. It will help you and help us.

                1 Reply Last reply
                2

                • Login

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