[英]how to suppress console output from QWebEngineView errors?
如果我從不同工作目錄中的 Python 實例創建 QWebEngineView 實例,則會收到以下錯誤:
[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
但與此同時,我該如何抑制此消息? 我嘗試更改QtCore.qInstallMessageHandler
和x.page().javaScriptConsoleMessage = lambda self, level, msg, line, sourceID: None
,均未影響此消息。
一種可能的解決方案是提高鉻日志的級別:
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()
# ...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.