如何抑制 QWebEngineView 错误的控制台输出? [英] how to suppress console output from QWebEngineView errors?

查看:61
本文介绍了如何抑制 QWebEngineView 错误的控制台输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我从不同工作目录中的 Python 实例创建 QWebEngineView 实例,则会收到以下错误:

I get the following error if I create a QWebEngineView instance from Python instances in different working directories:

[2452:9872:1108/052617.050:ERROR:cache_util_win.cc(21)] Unable to move the cache: Access is denied. (0x5)
[2452:9872:1108/052617.050:ERROR:cache_util.cc(135)] Unable to move cache folder C:\Users\Adam\AppData\Local\python\QtWebEngine\Default\GPUCache to C:\Users\Adam\AppData\Local\python\QtWebEngine\Default\old_GPUCache_000
[2452:9872:1108/052617.051:ERROR:disk_cache.cc(184)] Unable to create cache
[2452:9872:1108/052617.056:ERROR:shader_disk_cache.cc(606)] Shader Cache Creation failed: -2

from PyQt5 import QtCore, QtGui, QtWidgets, QtWebEngineWidgets
from PyQt5.QtCore import Qt
app = QtWidgets.QApplication([])
x = QtWebEngineWidgets.QWebEngineView()
x.load(QtCore.QUrl('http://example.com/'))

这似乎是一个已知问题,将在 QT6 中修复:https://bugreports.qt.io/browse/QTBUG-66014

It seems this is a known issue and will be fixed in QT6: https://bugreports.qt.io/browse/QTBUG-66014

但与此同时,我该如何抑制此消息?我尝试更改 QtCore.qInstallMessageHandlerx.page().javaScriptConsoleMessage = lambda self, level, msg, line, sourceID: None,均未影响此消息.>

But in the meantime, how can I suppress this message? I tried changing QtCore.qInstallMessageHandler and also x.page().javaScriptConsoleMessage = lambda self, level, msg, line, sourceID: None, neither affected this message.

推荐答案

一种可能的解决方案是提高 Chromium 日志的级别:

One possible solution is to raise the level of the chromium log:

import os
from PyQt5 import QtCore, QtGui, QtWidgets, QtWebEngineWidgets

os.environ["QTWEBENGINE_CHROMIUM_FLAGS"] = "--enable-logging --log-level=3"
app = QtWidgets.QApplication([])
x = QtWebEngineWidgets.QWebEngineView()
# ...

这篇关于如何抑制 QWebEngineView 错误的控制台输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆