From 25ff525cc910f7d2a764b4a04c871a5b2b087f7e Mon Sep 17 00:00:00 2001 From: evandrocoan Date: Sun, 31 May 2020 14:40:05 -0300 Subject: [PATCH 1/2] 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) From 5bec874a7b35e4f7394c57d2eafb0fa2536b71e9 Mon Sep 17 00:00:00 2001 From: evandrocoan Date: Sun, 31 May 2020 15:50:57 -0300 Subject: [PATCH 2/2] Set to also print the correct QT log message category --- qt/aqt/__init__.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/qt/aqt/__init__.py b/qt/aqt/__init__.py index 3f9090f30..145e52e35 100644 --- a/qt/aqt/__init__.py +++ b/qt/aqt/__init__.py @@ -325,7 +325,23 @@ def setupGL(pm): ctypes.CDLL("libGL.so.1", ctypes.RTLD_GLOBAL) # catch opengl errors - def msgHandler(type, ctx, msg): + def msgHandler(category, ctx, msg): + if category == QtDebugMsg: + category = "debug" + elif category == QtInfoMsg: + category = "info" + elif category == QtWarningMsg: + category = "warning" + elif category == QtCriticalMsg: + category = "critical" + elif category == QtDebugMsg: + category = "debug" + elif category == QtFatalMsg: + category = "fatal" + elif category == QtSystemMsg: + category = "system" + else: + category = "unknown" context = "" if ctx.file: context += f"{ctx.file}:" @@ -344,7 +360,7 @@ def setupGL(pm): pm.nextGlMode() return else: - print(f"qt: {msg} {context}") + print(f"Qt {category}: {msg} {context}") qInstallMessageHandler(msgHandler)