QWebEngineUrlSchemeHandler 类是处理自定义 URL 方案的基类。 更多...
头: | #include <QWebEngineUrlSchemeHandler> |
CMake: |
find_package(Qt6 COMPONENTS WebEngineCore REQUIRED)
target_link_libraries(mytarget PRIVATE Qt6::WebEngineCore) |
qmake: | QT += webenginecore |
Since: | Qt 5.6 |
继承: | QObject |
QWebEngineUrlSchemeHandler (QObject * parent = nullptr) | |
virtual | ~QWebEngineUrlSchemeHandler () |
virtual void | requestStarted (QWebEngineUrlRequestJob * request ) = 0 |
要实现自定义 URL 方案为 QtWebEngine , you first have to create an instance of QWebEngineUrlScheme and register it using QWebEngineUrlScheme::registerScheme ().
注意: Make sure that you create and register the scheme object before QGuiApplication or QApplication 对象被实例化。
Then you must create a class derived from QWebEngineUrlSchemeHandler, and reimplement the requestStarted () 方法。
Finally, install the scheme handler object via QWebEngineProfile::installUrlSchemeHandler () 或 QQuickWebEngineProfile::installUrlSchemeHandler ().
class MySchemeHandler : public QWebEngineUrlSchemeHandler { public: MySchemeHandler(QObject *parent = nullptr); void requestStarted(QWebEngineUrlRequestJob *request) { // .... } }; int main(int argc, char **argv) { QWebEngineUrlScheme scheme("myscheme"); scheme.setSyntax(QWebEngineUrlScheme::Syntax::HostAndPort); scheme.setDefaultPort(2345); scheme.setFlags(QWebEngineUrlScheme::SecureScheme); QWebEngineUrlScheme::registerScheme(scheme); // ... QApplication app(argc, argv); // ... // installUrlSchemeHandler does not take ownership of the handler. MySchemeHandler *handler = new MySchemeHandler(parent); QWebEngineProfile::defaultProfile()->installUrlSchemeHandler("myscheme", handler); }
另请参阅 QWebEngineUrlScheme and WebEngine Widgets WebUI 范例 .
构造新 URL 方案处理程序。
创建处理程序采用父级 parent .
[虚拟]
QWebEngineUrlSchemeHandler::
~QWebEngineUrlSchemeHandler
()
删除自定义 URL 方案处理程序。
[pure virtual]
void
QWebEngineUrlSchemeHandler::
requestStarted
(
QWebEngineUrlRequestJob
*
request
)
This method is called whenever a request request for the registered scheme is started.
This method must be reimplemented by all custom URL scheme handlers. The request is asynchronous and does not need to be handled right away.
另请参阅 QWebEngineUrlRequestJob .