PDA

View Full Version : Event Loop started in slot function



elizabeth.h1
21st October 2009, 13:56
Hello

Consider the following code :



MyDlg::OnOkBtn()
{
QEventLoop loop;
loop.exec();
this->someBtn->setEnabled(true); <----- 1
}

MyDlg::closeEvent(QCloseEvent*)
{
deleteLater();
}


In this code if the user closes the dialog while the event loop is running the dialog will be deleted after OnOkBtn slot returns, because DefferedDelete is not processed in local event loops. So the code is safe.

But now consider that instead QEventLoop I am using some third party library function which inside its implementation starts its own event loop. In that case if I close the dialog ( X Close) while the third party event loop is running, the dialog will be immediately deleted and control of execution will return in < ------1 , which is wrong because the dialog is already deleted.

QUESTION: How to make the dialog to be deleted AFTER OnOkBtn slot returns , when using external local event loop?

ONE POSSIBLE SOLUTION :
I suppose that Qt increments some variable in QEventLoop.exec ,and decrements the variable when the event loop object is exited. So when processing the Deffered Delete event it checks with this variable whether to delete the object.
Maybe I should keep such variable of my own?

Thanks for your time