Print stacktrace on Qt warnings.

This commit is contained in:
Florian Bruhin 2015-02-24 07:12:25 +01:00
parent c5a2039da4
commit caad56c978

View File

@ -26,6 +26,7 @@ import logging
import contextlib
import collections
import faulthandler
import traceback
from PyQt5.QtCore import (QtDebugMsg, QtWarningMsg, QtCriticalMsg, QtFatalMsg,
qInstallMessageHandler)
@ -294,8 +295,16 @@ def qt_message_handler(msg_type, context, msg):
msg += ("\n\nOn Archlinux, this should fix the problem:\n"
" pacman -S libxkbcommon-x11")
faulthandler.disable()
try:
frame = sys._getframe(1)
except (AttributeError, ValueError):
# sys._getframe might not exist in some Python implementations.
# It could raise ValueError if the stack is less than one level deep -
# this SHOULD never happen, but we're better safe than sorry here.
frame = None
stack = ''.join(traceback.format_stack(f=frame))
record = qt.makeRecord(name, level, context.file, context.line, msg, None,
None, func)
None, func, sinfo=stack)
qt.handle(record)