PyQt: No error msg (traceback) on exit

This is probably due to changes in the way exceptions are dealt with in PyQt-5.5. To quote from the PyQt5 Docs:

In PyQt v5.5 an unhandled Python exception will result in a call to
Qt’s qFatal() function. By default this will call abort() and the
application will terminate. Note that an application installed
exception hook will still take precedence.

When I run your example in a normal console, this is what I see:

$ python test.py
Traceback (most recent call last):
  File "test.py", line 213, in testfunc
    print(9/0)
ZeroDivisionError: division by zero
Aborted (core dumped)

So the main difference is that the application will now immediately abort when encountering an unhandled exception (i.e. just like a normal python script would). Of course, you can still control this behaviour by using a try/except block or globally by overriding sys.excepthook.

If you’re not seeing any traceback, this may be due to an issue with the Python IDE you’re using to run your application.

PS:

As a bare minimum, the old PyQt4 behaviour of simply printing the traceback to stdout/stderr can be restored like this:

def except_hook(cls, exception, traceback):
    sys.__excepthook__(cls, exception, traceback)

if __name__ == "__main__":

    import sys
    sys.excepthook = except_hook

Leave a Comment