def qtMessageHandler(msg_type, msg_log_context, msg_string): """Forwards Qt messages to Python logging system.""" # Convert Qt msg type to logging level log_level = [logging.DEBUG, logging.WARNING, logging.ERROR, logging.FATAL][int(msg_type)] qtcl = logging.getLogger(msg_log_context.category or "qt.???") # Some information may not be available unless using a PyQt debug build. # See: https://www.riverbankcomputing.com/static/Docs/PyQt5/api/qtcore/qmessagelogcontext.html if QLibraryInfo.isDebugBuild(): qtcl.log( logging.DEBUG, ' @ {0} : {1}'.format( (msg_log_context.file or "<unknown source file>"), msg_log_context.line)) qtcl.log( logging.DEBUG, ' ! {0}'.format((msg_log_context.function or "<unknown function>"))) qtcl.log(log_level, msg_string)
from PyQt5.QtCore import QLibraryInfo, QCoreApplication from pprint import pprint # QLibraryInfo isn't always valid until a QCoreApplication is # instantiated. app = QCoreApplication([]) paths = [x for x in dir(QLibraryInfo) if x.endswith('Path')] location = {x: QLibraryInfo.location(getattr(QLibraryInfo, x)) for x in paths} try: version = QLibraryInfo.version().segments() except AttributeError: version = None pprint({ 'isDebugBuild': QLibraryInfo.isDebugBuild(), 'version': version, 'location': location, })