[Interest] App. is running after an exception is thrown.

Constantin Makshin cmakshin at gmail.com
Fri Jul 26 22:58:19 CEST 2013


The "show" event is synchronous, i.e. it's not queued and showEvent() is
called almost directly from show()'s internals. That means things in your
code happen in this order:
1) you call show();
2) at one place inside show() there is a call to
QCoreApplication::sendEvent() which in turn calls your showEvent();
3) your showEvent() throws an exception;
4) control goes to the "catch" block which calls QCoreApplication::quit();
5) QCoreApplication::exit() sees there's no active event loops and returns
without doing anything;
6) you call QCoreApplication::exec() which starts an event loop.

The exception prevents show() from finishing its work so your windows
remains invisible. But it still exists (it wasn't shown, but nobody closed
it either), so exec() happily runs the event loop, not knowing the
application is in an unusable state.
On Jul 27, 2013 12:18 AM, "Alexander Syvak" <alexander.svk at gmail.com> wrote:

> So the a.exec() enters the event loop. Then the handler showEvent(QEvent*)
> is executed. The std::runtime_error is thrown out of the handler to the
> point of the previous call.
> The exception is caught inside the main() function. The dialog is thus not
> shown, but start executing again.
>
>
> 2013/7/26 Constantin Makshin <cmakshin at gmail.com>
>
>> QCoreApplication::quit(), being an "alias" to QCoreApplication::exit(0),
>> does nothing outside an event loop which in your case is started afterwards.
>> On Jul 26, 2013 10:20 PM, "Alexander Syvak" <alexander.svk at gmail.com>
>> wrote:
>>
>>> Hello,
>>>
>>> after calling w.show() there's method redefined void event_dlg::
>>> showEvent(QShowEvent *). In this method there's an exception thrown.
>>> The process does not terminate.
>>> Can anyone througly explain why is the job running after calling either
>>> close() of the only one and thus the last window (event_dlg w) or quit() of
>>> the QApplication a?
>>>
>>> #include "event_dlg.h"
>>>
>>> #include <QApplication>
>>>
>>> #include <QMessageBox>
>>>
>>> #include <QDebug>
>>>
>>> int main(int argc, char *argv[])
>>>
>>> {
>>>
>>>     QApplication a(argc, argv);
>>>
>>>     event_dlg w;
>>>
>>>     try
>>>
>>>     {
>>>
>>>         w.set_config_file("./events.xml");
>>>
>>>         w.show();
>>>
>>>     }
>>>
>>>     catch ( std::runtime_error & e )
>>>
>>>     {
>>>
>>> //        QMessageBox msgBox;
>>>
>>> //        msgBox.setText(e.what());
>>>
>>> //        msgBox.exec();
>>>
>>> //        qDebug() << w.close();
>>>
>>>
>>>         a.quit();
>>>
>>>     }
>>>
>>>         return a.exec();
>>>
>>> }
>>>
>>>
>>>
>>> _______________________________________________
>>> Interest mailing list
>>> Interest at qt-project.org
>>> http://lists.qt-project.org/mailman/listinfo/interest
>>>
>>>
>> _______________________________________________
>> Interest mailing list
>> Interest at qt-project.org
>> http://lists.qt-project.org/mailman/listinfo/interest
>>
>>
>
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20130727/0bc9624d/attachment.html>


More information about the Interest mailing list