[PyQt] QApplication.notify exception?
Giuseppe Corbelli
corbelligiuseppe at mesdan.it
Mon May 27 15:27:09 BST 2019
On 5/26/19 10:37 PM, 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 added an exception handler to a sub-classed QApplication like so:
>
> class MyApplication(data.QApplication):
> def notify(self, obj, event):
> try:
> return super().notify(obj, event)
> except:
> print("Unexpected Error")
> traceback.print_exc()
> sys.stdout.flush()
> return False
>
> and it prints:
>
> |Unexpected Error Traceback (most recent call last): File
> "myfile.py", line X, in notify return super().notify(obj, event)
> RuntimeError: wrapped C/C++ object of type QObject has been deleted|
>
> Any ideas of how to solve this problem?
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
More information about the PyQt
mailing list