[SOLVED] QDialog hide(), exec() and show() resulting in unexpected behavior
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:
(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
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.
@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...
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.
That is just the way dialogues work. It might be easier to implement your own widget to achieve the functionality you need.
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.
int ret = d1.exec();
if(ret == MAGIC_NUMBER)
Note: The second dialog returns a special value to indicate we will show the third dialog now.
@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:
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?
Well, by subclassing and adding stuff to QDialog you did implement a new widget, didn't you :)
To follow utcenter's advice, I did implement a new widget. See http://richelbilderbeek.nl/CppExerciseQtHideAndShow3Answer.htm for the QtHideAndShowDialog class.