是否可以在WebEngineView中获取点击链接的URL?

时间:2016-04-07 19:21:32

标签: qt qml qtwebengine qt5.6

我注意到在Qt版本5.4中,WebView有一个名为navigationRequired的信号,它在参数中有一个点击的URL。在新的WebView和WebEngineView中,没有这样的信号。我也没有找到任何替代方案。

有没有办法在Qt 5.6中获得点击链接的网址?

1 个答案:

答案 0 :(得分:0)

重新实施acceptNavigationRequest的方法QWebEnginePage

class MyQWebEnginePage : public QWebEnginePage
{
    Q_OBJECT

public:
    MyQWebEnginePage(QObject* parent = 0) : QWebEnginePage(parent){}

    bool acceptNavigationRequest(const QUrl & url, QWebEnginePage::NavigationType type, bool)
    {
        if (type == QWebEnginePage::NavigationTypeLinkClicked)
        {
            // retrieve the url here
            return false;
        }
        return true;
    }
};
相关问题