[Development] Allowing event delivery prior to and after QCoreApplication

Thiago Macieira thiago.macieira at intel.com
Wed Apr 15 17:11:27 CEST 2015


On Wednesday 15 April 2015 15:01:29 Julien Cugnière wrote:
> > But this is untested and unsupported. DO NOT throw through the event loop
> > and DO NOT throw back to the signal-slot delivery mechanism. We will not
> > deal with bug reports that this does not work. I may accept patches that
> > fix this, provided they don't introduce performance issues.
> 
> So just to make sure I understand it correctly, the following :
> 
>     bool SomeApplication::notify(QObject *object, QEvent *event)
>     {
>         try {
>             return QCoreApplication::notify(object, event);
>         }
>         catch (const Exception& e) {
>             writeLog(e.message());
>             return true;
>         }
>     }
> 
> Works for the moment (we use with Qt 5.3 just fine), but is not
> supported anymore, and has no official replacement. And with your
> change, it will stop working entirely. Any application relying on this
> will have to either add hundreds of thousands of try/catch all over
> the place (in all slots and event handlers, very error-prone), or be
> redesigned from scratch to not use exceptions.

Not exactly. It all depends on what you define to be "works". I don't consider 
resuming the event loop to be "works". I think that an uncaught exception 
should exit the event loop and cause the application to exit, so I consider 
your code above broken. It should rethrow after logging.

But let's assume you have a good reason for continuing the event loop. You're 
now in unsupported territory because you caught an exception in the middle of 
the loop and resumed operations.

The code above will continue to work for the main thread, but will stop 
working for auxiliary threads. And there will be no work around. You will need 
to do the right thing and stop any exceptions from going back to the signal-
slot mechanism and the event delivery mechanism.

If the problem is exceptions, we can simply add the exception protection 
elsewhere in the stack, closer to where we actually call out to the event 
handler or the slot.

> For the software we develop at work, we will probably end up patching
> our copy of Qt, as rewriting everything will be prohibitive, and we
> don't need QtDBUS, or post-application event delivery.

Do you need OpenGL or X11? Those use threads and they will probably continue 
running even after your SomeApplication class's destructor has begun, which 
means they may call your notify() during the destructor, including just after 
it finished and ~QApplication began.

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center




More information about the Development mailing list