Re: QApplication.notify exception?

Giuseppe Corbelli <[email protected]>
Newsgroups gmane.comp.python.pyqt-pykde
Message-ID <[email protected]>
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
_______________________________________________
PyQt mailing list    [email protected]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.