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] QDialog hide(), exec() and show() resulting in unexpected behavior
QtWS25 Last Chance

[SOLVED] QDialog hide(), exec() and show() resulting in unexpected behavior

Scheduled Pinned Locked Moved General and Desktop
9 Posts 4 Posters 6.3k 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.
  • R Offline
    R Offline
    richelbilderbeek
    wrote on last edited by
    #1

    Dear fellow programmers,

    I want to do the following:

    • hide the current dialog
    • exec a new dialog (that is: showing a new dialog modally)
    • show the current dialog again

    From the bugreport https://bugreports.qt-project.org/browse/QTBUG-3657 I learned that hiding (QDialog::Hide) a dialog causes QDialog::exec to return, resulting in -for me- unexpected behavior .

    Especially this code seems natural to me, yet the bug report stated it is intended to always close the current dialog (SecondDialog), instead of showing it:

    @
    void SecondDialog::on_button_goto_third_clicked()
    {
    ThirdDialog d;
    this->hide();
    d.exec();
    this->show();
    }
    @

    (see http://richelbilderbeek.nl/CppExerciseQtHideAndShow2.htm for full code and project download)

    How do I work around this intended behavior?

    Thanks for your help, Bilderbikkel

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

      if d.exec() is modal it will be placed on the parent and hold all inputs from the second dialog. So, don't hide it at all and let the third dialog be put above the second one?
      Maybe an other option is to run the third dialog in a different thread and wait in the second dialog until it is finished? Never tried it before, just an idea.
      Greetz

      Greetz, Jeroen

      1 Reply Last reply
      0
      • R Offline
        R Offline
        richelbilderbeek
        wrote on last edited by
        #3

        @Jeroentje:Thanks for your suggestion. Yet, I know exec() blocks input to the parent windows, but I just not to see those parent windows it at all...

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

          I thought you might say that ;-)
          If I have a great idea I'll let you know.
          Let me know if you fixed it, might need it myself in the future.

          Greetz, Jeroen

          1 Reply Last reply
          0
          • U Offline
            U Offline
            utcenter
            wrote on last edited by
            #5

            That is just the way dialogues work. It might be easier to implement your own widget to achieve the functionality you need.

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

              If I understand correctly, you want the second dialog to show a third one, but the second dialog is supposed to be hidden, while the third one is showing. Can't you just close() the second dialog and let the primary one (Main window?) show the third dialog? And then, after the third one has closed, just show the second one again.

              @void MainDialog::foo()
              {
              for(;;)
              {
              SecondDialog d1;
              int ret = d1.exec();
              if(ret == MAGIC_NUMBER)
              {
              ThirdDialog d2;
              d2.exec();
              }
              else
              {
              break;
              }
              }
              }@

              Note: The second dialog returns a special value to indicate we will show the third dialog now.

              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
              • R Offline
                R Offline
                richelbilderbeek
                wrote on last edited by
                #7

                @MuldeR: thanks for your suggestion, but it wouldn't scale: for example, if I would like to put a dialog before the first one again.

                I did find a solution and posted it here:

                http://richelbilderbeek.nl/CppExerciseQtHideAndShow2Answer.htm

                It involves adding two boolean member variables, two signals and two slots and calling QDialog::exec from a while loop.

                @utcenter: would you agree to prefer this over implementing a new widget?

                Cheers, Bilderbikkel

                1 Reply Last reply
                0
                • U Offline
                  U Offline
                  utcenter
                  wrote on last edited by
                  #8

                  Well, by subclassing and adding stuff to QDialog you did implement a new widget, didn't you :)

                  1 Reply Last reply
                  0
                  • R Offline
                    R Offline
                    richelbilderbeek
                    wrote on last edited by
                    #9

                    To follow utcenter's advice, I did implement a new widget. See http://richelbilderbeek.nl/CppExerciseQtHideAndShow3Answer.htm for the QtHideAndShowDialog class.

                    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