Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Popup a qmessagebox from a qmessagebox

    General and Desktop
    5
    10
    2095
    Loading More Posts
    • 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
      bear234 last edited by

      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 Reply Quote 0
      • Jeroentjehome
        Jeroentjehome last edited by

        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 Reply Quote 0
        • sierdzio
          sierdzio Moderators last edited by

          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 Reply Quote 0
          • B
            bear234 last edited by

            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 Reply Quote 0
            • B
              bear234 last edited by

              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 Reply Quote 0
              • sierdzio
                sierdzio Moderators last edited by

                [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 Reply Quote 0
                • raven-worx
                  raven-worx Moderators last edited by

                  [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 Reply Quote 0
                  • B
                    bear234 last edited by

                    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 Reply Quote 0
                    • B
                      bear234 last edited by

                      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 Reply Quote 0
                      • T3STY
                        T3STY last edited by

                        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 Reply Quote 0
                        • First post
                          Last post