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
Python PyQt5: How to show an error message with PyQt5
Qt includes an error-message specific dialog class QErrorMessage
which you should use to ensure your dialog matches system standards. To show the dialog just create a dialog object, then call .showMessage()
. For example:
error_dialog = QtWidgets.QErrorMessage()
error_dialog.showMessage('Oh no!')
Here is a minimal working example script:
import PyQt5
from PyQt5 import QtWidgets
app = QtWidgets.QApplication([])
error_dialog = QtWidgets.QErrorMessage()
error_dialog.showMessage('Oh no!')
app.exec_()
Related Topics
(Z3Py) Checking All Solutions for Equation
Difference in Boto3 Between Resource, Client, and Session
Equivalent of a Python Dict in R
Find in Files Using Ruby or Python
Call a Function with Argument List in Python
How to Execute a Python Script from the Django Shell
Python Pandas: Convert Rows as Column Headers
Parameterized Queries with Psycopg2/Python Db-API and Postgresql
Python Locale Error: Unsupported Locale Setting
Python How to Parse CSS File as Key Value
Dealing with the Class Imbalance in Binary Classification
Using Perl, Python, or Ruby, How to Write a Program to "Click" on the Screen at Scheduled Time
How to Import CSV Data into Django Models
Pythonic Way of Checking If a Condition Holds for Any Element of a List