PDA

View Full Version : What is meant by Local Event loop in Modal Dialog Context?



blue_sky
26th December 2013, 16:55
Qt doc says:
void QDialog::done ( int r ) [virtual slot]

Closes the dialog and sets its result code to r. If this dialog is shown with exec(), done() causes the local event loop to finish, and exec() to return r.
myDialog.exec();

inside myDialog slots..

{
///////
done(1);//here the Dialog invisible
QProgressDialog dia;
////dialog related parameters
foreach(---){
//update progress ba
qApp->processEvents();
//////
}

}
what is the behavior of processEvents() after done() and before done() with above QProgressbar?how events are handled in both the cases?

anda_skoa
26th December 2013, 19:47
That doesn't look like something you would want to have in any pprogram of yours.

Calling done but keeping operating the dialog is not a good idea. If the dialog is allocated on the stack it will be deleted while this code still executes.

If you want to hide the dialog call hide() and call done() when you are done.

Cheers,
_

ChrisW67
27th December 2013, 00:09
what is the behavior of processEvents() after done() and before done() with above QProgressbar?

A long-running for loop blocks the normal Qt event loop so painting and user interaction cannot function. The processEvents() inside the for loop ensures that the GUI is responsive and able to update while the for loop executes. In this particular scenario it would not be necessary if you are calling setValue() to update the progress bar: it calls processEvents() internally.

There is no processEvents() before done() is called in your snippet.

Consider processing the results from the modal dialog in the location that called exec() not inside the dialog class.

blue_sky
27th December 2013, 13:26
I wanted to know the behaviour of processEvents() before done(),as the local event loop is alive. So what is the behaviour if done() is called, but codes executing with procesEvents().Thanks in advance.


A long-running for loop blocks the normal Qt event loop so painting and user interaction cannot function. The processEvents() inside the for loop ensures that the GUI is responsive and able to update while the for loop executes. In this particular scenario it would not be necessary if you are calling setValue() to update the progress bar: it calls processEvents() internally.

There is no processEvents() before done() is called in your snippet.

Consider processing the results from the modal dialog in the location that called exec() not inside the dialog class.