【问题标题】:how to suppress console output from QWebEngineView errors?如何抑制 QWebEngineView 错误的控制台输出?
【发布时间】:2021-02-20 12:16:03
【问题描述】:

如果我从不同工作目录中的 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.qInstallMessageHandlerx.page().javaScriptConsoleMessage = lambda self, level, msg, line, sourceID: None,均未影响此消息。

【问题讨论】:

  • 尝试在app = QtWidgets.QApplication([])之前添加import os os.environ["QTWEBENGINE_CHROMIUM_FLAGS"] = "--disable-logging"
  • @eyllanesc 仍然收到相同的消息screencast.com/t/rHeWHPoGvG
  • @eyllanesc 我尝试了一些其他标志并尝试将标志直接传递给应用程序 (pastebin.com/kcw4Tfwt),但这些标志似乎都没有任何效果,似乎它们没有被应用到QWebEngineView...您还有其他想法吗?
  • 试试:os.environ["QTWEBENGINE_CHROMIUM_FLAGS"] = "--enable-logging --log-level=3"
  • 是的,那个有效!我猜不支持很多标志,但 --log-level 是。再次感谢@eyllanesc :)

标签: python pyqt pyqt5 qwebengineview


【解决方案1】:

一种可能的解决方案是提高铬原木的等级:

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()
# ...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-15
    • 1970-01-01
    相关资源
    最近更新 更多