Let `f` and `h` be Python functions and `g` be a function of Qt. If
f() -> g() -> h()
(where "`->`" means "calls"), and an exception occurs in `h()`, then the
traceback does not contain `f`. This can make debugging very difficult.
This version of fbs adds a custom `excepthook` that adds the missing
traceback entries. You can change it by overwriting the
`cached_property` `ApplicationContext.excepthook`.
The code below can be used to reproduce the `f() -> g() -> h()`
problem. It opens a window with a button. When you click it, an error
occurs whose traceback does not include `f()`.
The problem described here is not specific to PyQt5 - It occurs for
PySide2 as well. To see this, replace `PyQt5` by `PySide2` below.
from PyQt5.QtWidgets import *
from PyQt5.QtCore import Qt
class Window(QWidget):
def __init__(self):
super().__init__()
btn = QPushButton('Click me', self)
btn.clicked.connect(self.f)
def f(self, _):
self.inputMethodQuery(Qt.ImAnchorPosition)
def inputMethodQuery(self, query):
if query == Qt.ImAnchorPosition:
Make Qt call inputMethodQuery(ImCursorPosition).
This is our "g()":
return super().inputMethodQuery(query) "g()"
self.h()
def h(self):
raise Exception()
app = QApplication([])
window = Window()
window.show()
app.exec_()