QWebEngineUrlSchemeHandler 类

QWebEngineUrlSchemeHandler 类是处理自定义 URL 方案的基类。 更多...

头: #include <QWebEngineUrlSchemeHandler>
Since: Qt 5.6
继承: QObject

该类在 Qt 5.6 引入。

公共函数

QWebEngineUrlSchemeHandler (QObject * parent = Q_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 the 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 范例 .

成员函数文档编制

QWebEngineUrlSchemeHandler:: QWebEngineUrlSchemeHandler ( QObject * parent = Q_NULLPTR)

构造新 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 .