From 25ff525cc910f7d2a764b4a04c871a5b2b087f7e Mon Sep 17 00:00:00 2001 From: evandrocoan Date: Sun, 31 May 2020 14:40:05 -0300 Subject: [PATCH] Print qt context if it exists https://stackoverflow.com/questions/42561295/qt-error-is-printed-on-the-console-how-to-see-where-it-originates-from https://stackoverflow.com/questions/35894171/redirect-qdebug-output-to-file-with-pyqt5 https://anki.tenderapp.com/discussions/ankidesktop/42070-anki-closes-without-warning-when-importing-conflicting-shared-deck https://doc.qt.io/qt-5/qtglobal.html#qInstallMessageHandler --- qt/aqt/__init__.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/qt/aqt/__init__.py b/qt/aqt/__init__.py index b97a51a7c..3f9090f30 100644 --- a/qt/aqt/__init__.py +++ b/qt/aqt/__init__.py @@ -326,17 +326,25 @@ def setupGL(pm): # catch opengl errors def msgHandler(type, ctx, msg): + context = "" + if ctx.file: + context += f"{ctx.file}:" + if ctx.line: + context += f"{ctx.line}," + if ctx.function: + context += f"{ctx.function}" + if context: + context = f"'{context}'" if "Failed to create OpenGL context" in msg: QMessageBox.critical( None, "Error", - "Error loading '%s' graphics driver. Please start Anki again to try next driver." - % mode, + f"Error loading '{mode}' graphics driver. Please start Anki again to try next driver. {context}", ) pm.nextGlMode() return else: - print("qt:", msg) + print(f"qt: {msg} {context}") qInstallMessageHandler(msgHandler)