使用QWebEngineView出现大量警告及错误,求解决方案
QWebEngineView加载网页时警告与错误的解决方法
问题描述
使用QWebEngineView加载网页时,控制台输出大量警告及一条错误,相关代码和输出信息如下:
相关代码
webview.cpp
#include "webview.h" webview::webview(QWidget *parent) : QWebEngineView(parent) { } webview::~webview() { }
mainwindow.cpp
#include "mainwindow.h" #include "ui_mainwindow.h" #include "webview.h" #include <QFile> MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) { ui->setupUi(this); webView = new webview(this); webView->load(QUrl("http://www.google.com")); webView->resize(1024, 750); // webView->show(); } MainWindow::~MainWindow() { delete ui; }
main.cpp
#include "mainwindow.h" #include <QWebEngineView> #include <QApplication> int main(int argc, char *argv[]) { QApplication a(argc, argv); MainWindow w; w.resize(1024, 750); w.show(); return a.exec(); }
程序输出
js: Error with Permissions-Policy header: Origin trial controlled feature not enabled: 'unload'. [18236:18132:1023/152811.537:ERROR:render_process_impl.cc(281)] WebFrame LEAKED 1 TIMES js: The Cross-Origin-Opener-Policy header has been ignored, because the URL's origin was untrustworthy. It was defined either in the final response or a redirect. Please deliver the response using the HTTPS protocol. You can also use the 'localhost' origin instead. See https://www.w3.org/TR/powerful-features/#potentially-trustworthy-origin and https://html.spec.whatwg.org/#the-cross-origin-opener-policy-header. D3D11 WARNING: ID3D11Device::CreateInputLayout: The provided input signature expects to read an element with SemanticName/Index: 'TEXCOORD'/2 and component(s) of the type 'int32'. However, the matching entry in the Input Layout declaration, element[2], specifies mismatched format: 'R16G16_UINT'. This is not an error, since behavior is well defined: The element format determines what data conversion algorithm gets applied before it shows up in a shader register. Independently, the shader input signature defines how the shader will interpret the data that has been placed in its input registers, with no change in the bits stored. It is valid for the application to reinterpret data as a different type once it is in the vertex shader, so this warning is issued just in case reinterpretation was not intended by the author. [ STATE_CREATION WARNING #391: CREATEINPUTLAYOUT_TYPE_MISMATCH] D3D11 WARNING: ID3D11Texture2D1::SetPrivateData: Existing private data of same name with different size found! [ STATE_SETTING WARNING #55: SETPRIVATEDATA_CHANGINGPARAMS] D3D11 WARNING: ID3D11Texture2D1::SetPrivateData: Existing private data of same name with different size found! [ STATE_SETTING WARNING #55: SETPRIVATEDATA_CHANGINGPARAMS] D3D11 WARNING: Process is terminating. Using simple reporting. Please call ReportLiveObjects() at runtime for standard reporting. [ STATE_CREATION WARNING #0: UNKNOWN] D3D11 WARNING: Live Producer at 0x000001B01287FEE0, Refcount: 40. [ STATE_CREATION WARNING #0: UNKNOWN] D3D11 WARNING: Live Object at 0x000001B0128C7F20, Refcount: 3. [ STATE_CREATION WARNING #0: UNKNOWN] D3D11 WARNING: Live Object at 0x000001B012BE1690, Refcount: 0. [ STATE_CREATION WARNING #0: UNKNOWN] D3D11 WARNING: Live Object at 0x000001B012B77BF0, Refcount: 2. [ STATE_CREATION WARNING #0: UNKNOWN] D3D11 WARNING: Live Object at 0x000001B012B2C480, Refcount: 0. [ STATE_CREATION WARNING #0: UNKNOWN] D3D11 WARNING: Live Object at 0x000001B012B2DAD0, Refcount: 0. [ STATE_CREATION WARNING #0: UNKNOWN] D3D11 WARNING: Live Object at 0x000001B012BC4A80, Refcount: 0. [ STATE_CREATION WARNING #0: UNKNOWN] D3D11 WARNING: Live Object at 0x000001B00938A610, Refcount: 0. [ STATE_CREATION WARNING #0: UNKNOWN] ... D3D11 WARNING: Live Object : 159 [ STATE_CREATION WARNING #0: UNKNOWN]
解决方法
1. HTTP相关JS警告(Permissions-Policy、Cross-Origin-Opener-Policy)
- 原因:加载的HTTP协议站点属于非可信源,现代浏览器安全策略限制这类站点的权限头和跨域策略生效。
- 解决:将加载的URL改为HTTPS协议,修改mainwindow.cpp中的代码:
HTTPS属于可信源,可避免此类安全策略警告。webView->load(QUrl("https://www.google.com"));
2. WebFrame LEAKED错误
- 原因:WebEngine渲染进程资源未被正确清理,通常是因为webView的生命周期管理不当。
- 解决:
- 在MainWindow析构函数中先手动销毁webView,再删除ui:
MainWindow::~MainWindow() { delete webView; delete ui; } - 将webView添加到父窗口布局,让父窗口统一管理其生命周期,修改mainwindow.cpp构造函数:
webView = new webview(this); webView->load(QUrl("https://www.google.com")); setCentralWidget(webView); // 替代手动resize,让窗口管理大小
- 在MainWindow析构函数中先手动销毁webView,再删除ui:
3. D3D11相关警告
- 原因:这是Chromium内核使用Direct3D渲染时的内部调试警告,不影响功能,多为资源类型匹配或进程退出时的资源报告。
- 解决:
- 禁用D3D11调试输出,在main.cpp开头添加:
qputenv("QTWEBENGINE_CHROMIUM_FLAGS", "--disable-d3d11-debug"); - 或切换到OpenGL渲染,在main.cpp开头添加:
QApplication::setAttribute(Qt::AA_UseOpenGLES);
- 禁用D3D11调试输出,在main.cpp开头添加:
内容的提问来源于stack exchange,提问作者Jack
相关产品推荐
相关产品推荐

