[Qt-interest] Event Loop started in slot function
elizabeta petreska
elizabeta.petreska at gmail.com
Thu Oct 22 09:11:30 CEST 2009
Hello
Consider the following code :
MyDlg::OnOkBtn()
{
QEventLoop <http://doc.trolltech.com/latest/QEventLoop.html> loop;
loop.exec();
this->someBtn->setEnabled(true); <----- 1
}
MyDlg::closeEvent(QCloseEvent
<http://doc.trolltech.com/latest/QCloseEvent.html>*)
{
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.
After closing, if the event loop is terminated,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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20091022/fa2f3d3e/attachment.html
More information about the Qt-interest-old
mailing list