Qt如何获取发送者信号的发送者或如何知道QWebEngineView的loadStarted url?

时间:2017-11-01 14:18:00

标签: c++ qt signals-slots qwebengineview qwebenginepage

QWebEngineView的信号为void loadStarted()。它从QWebEnginePage收到时会发出此信号。 QWebEnginePage从QWebEnginePagePrivate重写此函数,其中它是void loadStarted(const QUrl& provisionalUrl,bool isErrorPage = false),但在QWebEnginePage类参数中,参数provisionalUrl标记为Q_UNUSED(),但我想知道它的值。我该怎么办?

1 个答案:

答案 0 :(得分:0)

如果你必须截取导航请求并按导航类型过滤它们,你可以做的最好是覆盖QWebEnginePage :: acceptNavigationRequest()虚函数。

https://doc.qt.io/qt-5/qwebenginepage.html#acceptNavigationRequest

class NavigationRequestOverride : public QWebEnginePage
{
public:
    NavigationRequestOverride(QObject* parent) : QWebEnginePage(parent) {}
protected:
    virtual bool acceptNavigationRequest(const QUrl &url, NavigationType type, bool isMainFrame)
    {
       // Here goes your logic
    }
};