QWebEngineUrlSchemeHandler 类

QWebEngineUrlSchemeHandler class is a base class for handling custom URL schemes. 更多...

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

公共函数

QWebEngineUrlSchemeHandler (QObject * parent = Q_NULLPTR)
virtual ~QWebEngineUrlSchemeHandler ()
virtual void requestStarted (QWebEngineUrlRequestJob * request ) = 0

静态公共成员

const QMetaObject staticMetaObject

额外继承成员

详细描述

QWebEngineUrlSchemeHandler class is a base class for handling custom URL schemes.

要实现自定义 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 .

[virtual] 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 .