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. Popup a qmessagebox from a qmessagebox
Forum Update on Monday, May 27th 2025

Popup a qmessagebox from a qmessagebox

Scheduled Pinned Locked Moved General and Desktop
10 Posts 5 Posters 2.6k 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.
  • B Offline
    B Offline
    bear234
    wrote on last edited by
    #1

    I set a button in the MainWindow
    when I click it, a messagebox will popup, which contains two buttons: yes and no
    then when I click yes, another messagebox will popup.
    BUT when the second messagebox popup, the first one will disappear. and if I close the second one, the first will come out.

    what I want is we can see the first one messagebox even if the second one popup but we can do nothing for the first one when the second one is not close.

    can u help me?
    thx in advance

    here is my code:
    @
    QMessageBox firstone;
    firstone.setStandardButtons(QMessageBox::Ok | QMessageBox::No);
    if(firstone.exec() == QMessageBox::Ok)
    {
    QMessageBox secondone;
    secondone.exec();
    }
    @

    1 Reply Last reply
    0
    • JeroentjehomeJ Offline
      JeroentjehomeJ Offline
      Jeroentjehome
      wrote on last edited by
      #2

      Hmm, the exec code will run until the OK or NO button is pressed, so it is strange that the first one reappears when the second one is closed.
      If you really want this to work, you should inherit a QMEssageBox class and alter the OK button signal to open a new messageBox if not already opened. The way you do so now it is not able to display both!

      Greetz, Jeroen

      1 Reply Last reply
      0
      • sierdzioS Offline
        sierdzioS Offline
        sierdzio
        Moderators
        wrote on last edited by
        #3

        That sounds like an annoying UI design decision, be careful :)

        To get that functionality, you need to subclass QMessageBox and open the second one from within the first, before it is killed. Should not be too hard, but you will need to experiment a bit.

        (Z(:^

        1 Reply Last reply
        0
        • B Offline
          B Offline
          bear234
          wrote on last edited by
          #4

          really? we have no other choice?

          this is not strange.
          imagine u are saving a file, a window where we can enter a filename will popup. but if there have been a file whose name is exactly what u just entered, another window will pupup and tell u : do u want to replace it? or something like this. and when this window is not close, the last window(where u enter the filename) is always there.

          [quote author="Jeroentje@home" date="1389963475"]Hmm, the exec code will run until the OK or NO button is pressed, so it is strange that the first one reappears when the second one is closed.
          If you really want this to work, you should inherit a QMEssageBox class and alter the OK button signal to open a new messageBox if not already opened. The way you do so now it is not able to display both![/quote]

          1 Reply Last reply
          0
          • B Offline
            B Offline
            bear234
            wrote on last edited by
            #5

            I got u.

            thx a lot.

            [quote author="sierdzio" date="1389963594"]That sounds like an annoying UI design decision, be careful :)

            To get that functionality, you need to subclass QMessageBox and open the second one from within the first, before it is killed. Should not be too hard, but you will need to experiment a bit.[/quote]

            1 Reply Last reply
            0
            • sierdzioS Offline
              sierdzioS Offline
              sierdzio
              Moderators
              wrote on last edited by
              #6

              [quote author="bear234" date="1389963777"]really? we have no other choice?

              this is not strange.
              imagine u are saving a file, a window where we can enter a filename will popup. but if there have been a file whose name is exactly what u just entered, another window will pupup and tell u : do u want to replace it? or something like this. and when this window is not close, the last window(where u enter the filename) is always there.
              [/quote]

              Yes, really. That is how it is being done in case you mentioned (although not using message boxes, but QDialogs).

              (Z(:^

              1 Reply Last reply
              0
              • raven-worxR Offline
                raven-worxR Offline
                raven-worx
                Moderators
                wrote on last edited by
                #7

                [quote author="bear234" date="1389963777"]really? we have no other choice?

                this is not strange.
                imagine u are saving a file, a window where we can enter a filename will popup. but if there have been a file whose name is exactly what u just entered, another window will pupup and tell u : do u want to replace it? or something like this. and when this window is not close, the last window(where u enter the filename) is always there.
                [/quote]

                i also would discourage from using message boxes for that.
                A more friendly solution would be to display a warning text (or an icon with an tooltip for example) under/beside the line edit saying that the file does already exist.
                And only enable the button to proceed when all requirements are fulfilled.

                I personally like such "inline" solutions the most rather than annoying popups.

                --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                If you have a question please use the forum so others can benefit from the solution in the future

                1 Reply Last reply
                0
                • B Offline
                  B Offline
                  bear234
                  wrote on last edited by
                  #8

                  OK I understand.

                  thx
                  [quote author="sierdzio" date="1389963869"][quote author="bear234" date="1389963777"]really? we have no other choice?

                  this is not strange.
                  imagine u are saving a file, a window where we can enter a filename will popup. but if there have been a file whose name is exactly what u just entered, another window will pupup and tell u : do u want to replace it? or something like this. and when this window is not close, the last window(where u enter the filename) is always there.
                  [/quote]

                  Yes, really. That is how it is being done in case you mentioned (although not using message boxes, but QDialogs).[/quote]

                  1 Reply Last reply
                  0
                  • B Offline
                    B Offline
                    bear234
                    wrote on last edited by
                    #9

                    thx a lot!

                    nice method.

                    [quote author="raven-worx" date="1389967933"][quote author="bear234" date="1389963777"]really? we have no other choice?

                    this is not strange.
                    imagine u are saving a file, a window where we can enter a filename will popup. but if there have been a file whose name is exactly what u just entered, another window will pupup and tell u : do u want to replace it? or something like this. and when this window is not close, the last window(where u enter the filename) is always there.
                    [/quote]

                    i also would discourage from using message boxes for that.
                    A more friendly solution would be to display a warning text (or an icon with an tooltip for example) under/beside the line edit saying that the file does already exist.
                    And only enable the button to proceed when all requirements are fulfilled.

                    I personally like such "inline" solutions the most rather than annoying popups. [/quote]

                    1 Reply Last reply
                    0
                    • T3STYT Offline
                      T3STYT Offline
                      T3STY
                      wrote on last edited by
                      #10

                      Why not calling the second MessageBox outside the first one?
                      I would open the first MessageBox and wait for it to be closed. When closed a buttonClicked() signal is emitted. You connect a slot to the first QMessageBox's buttonClicked() signal, and in that slot you call the second QMessageBox.
                      @QMessageBox firstMessage;
                      (...)
                      connect(&firstMessage, SIGNAL(buttonClicked(QAbstractButton *)), this, SLOT(onFirstMsgClosed(QAbstractButton * button)));
                      (...)
                      slots:
                      void onFirstMsgClosed(QAbstractButton * button){
                      QMessageBox secondMessage;
                      secondMessage.show();
                      }
                      @

                      The code above is quite incomplete, but I hope you get it.

                      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