【发布时间】:2016-04-07 19:21:32
【问题描述】:
我注意到在 Qt 5.4 版中,WebView 有一个名为navigationRequired 的信号,它的参数中有一个点击的 URL。在新的 WebView 和 WebEngineView 中,没有这样的信号。我也没有找到任何替代方案。
在 Qt 5.6 中有什么方法可以获取点击链接的 URL 吗?
【问题讨论】:
标签: qt qml qtwebengine qt5.6
我注意到在 Qt 5.4 版中,WebView 有一个名为navigationRequired 的信号,它的参数中有一个点击的 URL。在新的 WebView 和 WebEngineView 中,没有这样的信号。我也没有找到任何替代方案。
在 Qt 5.6 中有什么方法可以获取点击链接的 URL 吗?
【问题讨论】:
标签: qt qml qtwebengine qt5.6
重新实现QWebEnginePage的方法acceptNavigationRequest:
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;
}
};
【讨论】: