1

I've noticed that in Qt version 5.4, WebView has a signal named navigationRequired, which had a clicked URL in parameters. In the new WebView and WebEngineView, there is no such signal. I also haven't found any alternatives.

Is there any way to get a clicked link's URL in Qt 5.6?

IAmInPLS
  • 4,051
  • 4
  • 24
  • 57

1 Answers1

1

Reimplement the method acceptNavigationRequest of 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;
    }
};
IAmInPLS
  • 4,051
  • 4
  • 24
  • 57
  • So basically on every click in QML WebEngineView this method will be called? – Maksym Bulhakov Apr 14 '16 at 05:39
  • Why don't you try it? – IAmInPLS Apr 14 '16 at 06:31
  • sorry for such delayed question, but how do I use it? I mean, this is c++ class and I need to check it from qml. – Maksym Bulhakov Jun 01 '16 at 09:57
  • 1
    Oh ok. Then see this link : http://doc.qt.io/qt-5/qml-qtwebengine-webengineview.html#WebAction-prop. There are different actions that you can retrieve from your WebEngineView – IAmInPLS Jun 01 '16 at 10:11
  • 1
    Yes, indeed! Actions solve my problem. I just called WebEngineView.onLoadingChanged and checked whether loadRequest.status equals to LoadStartedStatus, and if so I called WebAction(Stop) and made a call from default browser. – Maksym Bulhakov Jun 08 '16 at 13:05