我用QWebEngineView加载一个url后,直接点击链接没有任何反应,要在链接上右键点击,然后通过菜单的Follow Link才能打开。初学Qt能力有限,找了QWebEngineView和QWebEnginePage的文档愣是没看到有相关的方法,求大家帮忙看看。
网上资料太少了,全是QWebView的,可是我用的是Qt5.6,已经没有这个模块了。
大家讲道理2017-04-17 14:37:11
In QWebEngineView
there are the following methods:
QWebEngineView *QWebEngineView::createWindow(QWebEnginePage::WebWindowType type)
This method will be triggered when the left mouse button is clicked. You can overload it and use your own implementation.
高洛峰2017-04-17 14:37:11
This bug seems to have nothing to do with the createWindow function.
In QWebEngineView, when a user clicks on a link on a web page, a signal will be triggered:
urlChanged(QUrl)
But QWebEngineView will not automatically load new links.
So you need to create a new slot function for urlChanged(QUrl) yourself and manually load the new link in the parameters yourself.
For example:
connect(m_pView, SIGNAL(urlChanged(QUrl)),
this, SLOT(onUrlChanged(QUrl)));
//Webpage link address
//Triggered by the user clicking on the webpage
//There is a problem with QWebEngineView. When the user clicks a link in the webpage, it only triggers the urlChanged(QUrl) signal
//Does not automatically load new Linking web pages requires manual loading
void MainWindow::onUrlChanged(const QUrl &url)
{
//地址栏的旧网址
QUrl old = QUrl( m_pURLEdit->text() );
//链接有变化才更新,用户点击网页里的新链接会触发
if(url != old)
{
m_pURLEdit->setText( url.toString() );
//用户点击了新网页,但是没自动加载,手动刷新
m_pView->load(url);//要放在if判断内部,否则容易无限刷新,死循环
}
qDebug()<<url;
}
**
**