Open Dialog and emit signal
-
Hello,
I am trying to open a dialog and emit a signal immediately so that some code can be executed within MainWindow while the dialog is open. Please advise on how it can be done.
@void MainWindow::open_dialog()
{
Ui::Dialog ap;
QDialog *diag = new QDialog;
ap.setupUi(diag);
diag->setModal(true);connect(this, SIGNAL(the_signal()), this, SLOT(edit_text())); while(diag->exec()) { emit the_signal(); }
}@
-
Hi,
If you want the MainWindow to react on something that happens in the Dialog the Dialog itself must issue the signal.
the diag->exec() will hold "execution" active there until the exec function is terminated by a user action (if there are ok/cancel or x button pressed).
Or if the MainWindow should emit the signal before the execution of the dialog.
greetz -
The signal in this case has to be emitted by MainWindow. So you are probably saying this isn't possible
-
Everything is possible ;-)
What you could try is to first emit the signal (after creation of QDialog) and then run the exec on the dialog. The exec will start the eventhandler on the dialog. Don't think this will work btw.
On the other hand, you could start a single timer (e.g. 100msec) in the MainWindow just before the exec on the dialog.
In the timerEvent of Mainwindow emit the signal you need in the dialog.
That should work without a problem if you ask me.
But why do you need this option anyway? Sounds a bit dodgy in object orientated programming. -
I need the option so as to have a dialog displaying a progressBar that shows progress for a function inside MainWindow without interference (the dialog blocks interaction). But I have now opted to disable all widgets and have the progressBar inside MainWindow itself.
Thanks Jeroentje@home for the help