[PyQt] QApplication.notify exception?

Matic Kukovec kukovecmatic at hotmail.com
Tue May 28 18:41:24 BST 2019


On Sun, May 26, 2019 at 04:52:20PM -0400, Kyle Altendorf wrote:
> On 2019-05-26 16:37, Matic Kukovec wrote:
>
> > Hi guys,
> >
> > I have an application that runs without a problem on Windows, but on
> > Linux it shows this message on exit:
> >
> > > Qt has caught an exception thrown from an event handler. Throwing
> > > exceptions from an event handler is not supported in Qt.
> > > You must not let any exception whatsoever propagate through Qt code.
> > > If that is not possible, in Qt 5 you must at least reimplement
> > > QCoreApplication::notify() and catch all exceptions there.
>
> I use sys.excepthook to provide a log and dialog for otherwise unhandled
> Python exceptions.  Maybe see if that can at least let you see what
> exception is causing trouble?  But I honestly haven't ever seen a reference
> to this message before...  :|

That message is coming from Qt, which doesn't know about Python exceptions.

I'm guessing it's referring to C++ exceptions, which you won't catch in Python
via an excepthook or "except".

So the question is why there's a C++ exception thrown, and from where... No
idea how to debug that to be honest. Maybe you can get gdb to break on any
exception or something?

Florian

The first step is to get some more information regarding the exception
trace. The exception traceback has tb_frame and tb_next attributes to
build a frames stack. Each frame has its own frame.f_code.co_name,
frame.f_code.co_filename, frame.f_lineno and local stack variables
(frame.f_locals).

--
Giuseppe Corbelli

Thanks for the suggestions guys!

I added a faulthandler to my application and added an exception handler in an overridden
QApplication.notify and it pointed me to a queue implementation i have, that uses signals/slots for input
and output, and it seems that a exception happens in there and only on Linux.
I'm still hunting it down, but at least now I know where to look.

This SO post also helped me to figure out that exceptions in a slot are sometimes not propagated up:
https://stackoverflow.com/questions/18740884/preventing-pyqt-to-silence-exceptions-occurring-in-slots


Thanks again,
Matic

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20190528/1ec59c81/attachment.html>


More information about the PyQt mailing list