I have a PyQt6 gui application. If I run it in a command window (I am working on Windows), I get log messages from Py(?)Qt:
(venv) PS C:\application> python .\main.py
QTableWidget: cannot insert an item that is already owned by another QTableWidget
QTableWidget: cannot insert an item that is already owned by another QTableWidget
...
If I run it in my IDE (pycharm) I do not see these messages. No exceptions either. I do not see any unintended behaviour in respect to the QTableWidget.
- How can I debug this?
- Who is sending these messages?
- Is there a way to route these messages into the application and the python logger?
CodePudding user response:
Firstly, make sure your IDE is configured to show error output. Secondly, the messages are shown by Qt due to bugs in your code. To make them go away, you can fix the bugs in the manner implied by the messages.
Qt never raises exceptions as such, so there's nothing to re-raise on the Python side. In general, Qt prefers to use return values to indicate success/failure (where possible), and otherwise outputs warning messages. For critical errors, it will abort execution (see qCritical and related functions for the exact circumstances under which this may happen).
To control the output of Qt messages, you can use qInstallMessageHandler.