QWebEngineUrlRequestInterceptor Class

QWebEngineUrlRequestInterceptor 类为 URL 拦截提供了一个抽象基类。更多

Header: #include <QWebEngineUrlRequestInterceptor>
CMake: find_package(Qt6 REQUIRED COMPONENTS WebEngineCore)
target_link_libraries(mytarget PRIVATE Qt6::WebEngineCore)
qmake: QT += webenginecore
继承: QObject

公共函数

QWebEngineUrlRequestInterceptor(QObject *p = nullptr)
virtual void interceptRequest(QWebEngineUrlRequestInfo &info) = 0

详细说明

实现QWebEngineUrlRequestInterceptor 接口并在配置文件中安装拦截器,可在 URL 请求到达 Chromium 网络堆栈之前拦截、阻止和修改 URL 请求。

您可以通过QWebEngineProfile::setUrlRequestInterceptor() 或QQuickWebEngineProfile::setUrlRequestInterceptor() 在配置文件上安装拦截器。

使用Qt WebEngine Widgets 模块时,QWebEnginePage::acceptNavigationRequest() 可提供更多接受或拦截请求的选项。

另请参阅 interceptRequest() 和QWebEngineUrlRequestInfo

成员函数文档

[explicit] QWebEngineUrlRequestInterceptor::QWebEngineUrlRequestInterceptor(QObject *p = nullptr)

创建一个新的 QWebEngineUrlRequestInterceptor 对象,父对象为p

[pure virtual] void QWebEngineUrlRequestInterceptor::interceptRequest(QWebEngineUrlRequestInfo &info)

重新实现该虚拟函数后,就可以拦截 URL 请求。该方法将拦截 URL 请求,直至处理完毕。

info 该函数包含 URL 请求的相关信息,并将在内部跟踪其成员是否被更改。

警告 主线程中对配置文件的所有方法调用都将阻塞,直到此函数执行完毕。

© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.