PDA

View Full Version : Working with multiple local QDialogs



Momergil
28th March 2013, 22:03
Hello!

I would like to declare two local QDialogs by pointers and show them at the same time, and only after the last of them is closed the reading of the code would proceed:



QDialog *dia1 = new QDialog(this);
dia1->configure...

QDialog *dia2 = new QDialog(this);
dia2->configure...

dia1->show();
dia2->show();

//The reading of the code stops here while the user uses the two dialogs as it pleases him, and after closing the last of the two the reading of the code proceeds

delete dia1;
delete dia2;


The problem is that I simple don't know how to this without causing some sort of bad consequence. If I try to use exec() for both of them, the second Dialog is opened only after closing the first. If I use show() for both, than the rest of the code will be read even with the dialogs still opened. If I set show() for the first and exec() for the second, than it's impossible to touch in the first QDialog; it will be blocked while I work with the second dialog. setWindowModality() doesn't seems to add any improvement to this situation.

Is there a possible way of doing this?


Thanks,

Momergil

ChiliPalmer
29th March 2013, 00:35
Hi,

this might be useless advice as I don't know the reason why you want to have the user close two dialogs after one another, but you might consider creating a QDialog subclass that consists of the contents of both your dialogs. Or, if dia1 is supposed to be shown before dia2, you might consider a QWizard.

Lykurg
29th March 2013, 14:11
Make dia1 and dia2 class members
make a function which set up the dialogs and show them
connect the hidden signals (or QDialog::accepted or or or) of the dialogs to a custom slot
there check, if both dialogs where closed/hidden. If so continue with your code.

Momergil
1st April 2013, 21:07
Hi,

this might be useless advice as I don't know the reason why you want to have the user close two dialogs after one another, but you might consider creating a QDialog subclass that consists of the contents of both your dialogs. Or, if dia1 is supposed to be shown before dia2, you might consider a QWizard.

Thanks Chili, but that is of no use for me. I want to give the user the option of moving the two dialogs as he wants around the desktop, not concentrating all data into one QDialog alone. And it's to be shown "at the same time", i.e. the user will be seeing both QDialogs in the screen, not the type of thing QWizard provides.

Added after 7 minutes:



Make dia1 and dia2 class members
...


yes, I know how to do this if I declare them class members, but as I put in my question, I'ld like to declare them local, as in my code example.

Added after 1 13 minutes:



Make dia1 and dia2 class members
make a function which set up the dialogs and show them
connect the hidden signals (or QDialog::accepted or or or) of the dialogs to a custom slot
there check, if both dialogs where closed/hidden. If so continue with your code.


Well, at the end I decided to follow this way. Nevertheless I'm still curious about the possibility of doing the way I asked about...

Thanks,

Momergil

d_stranz
1st April 2013, 23:35
Nevertheless I'm still curious about the possibility of doing the way I asked about...

Construct your dialog instances as local variables in the method where you show them.
Connect their accepted() (or rejected(), or whatever dialog closing signal you'd like to handle) signals to a slot (in any class).
In that slot, call "sender()->deleteLater()" to schedule the instance for deletion.

When control returns to the event loop, the dialog instance will be deleted. Same thing will happen for the other dialog when the user closes it.

See QObject::deleteLater().

Edit: since you will no longer have access to the dialog pointers anywhere except in the accept() slot, there's no way to check if the dialogs have been closed. I'd suggest you could do something simple like have an integer member variable. Set it to zero when you create and show the dialogs, then in the accept() slot, increment it. When it reaches 2, emit another signal that results in the continuation of your code.