Help: Workaround overrideCursor issue with WebEngine based viewer

QWebEngineViewer never sends a loadFinished signal (but a loadStarted
signal) when only the URL fragment changes (QTBUG-65223). Work around by
logging the last URL and recognizing that condition.

Task-number: QTCREATORBUG-19649
Change-Id: I7b96fe60f5c76ebffb36c23e8d62c6cb1aa515aa
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
Eike Ziller
2018-01-29 10:22:47 +01:00
parent d3f5f63a33
commit e7316c9fe7
2 changed files with 16 additions and 1 deletions

View File

@@ -34,6 +34,7 @@
#include <QBuffer>
#include <QContextMenuEvent>
#include <QCoreApplication>
#include <QTimer>
#include <QVBoxLayout>
#if QT_VERSION >= QT_VERSION_CHECK(5, 7, 0)
#include <QWebEngineContextMenuData>
@@ -89,7 +90,20 @@ WebEngineHelpViewer::WebEngineHelpViewer(QWidget *parent) :
setPalette(p);
connect(m_widget, &QWebEngineView::urlChanged, this, &WebEngineHelpViewer::sourceChanged);
connect(m_widget, &QWebEngineView::loadStarted, this, &WebEngineHelpViewer::slotLoadStarted);
connect(m_widget, &QWebEngineView::loadStarted, this, [this] {
slotLoadStarted();
// Work around QTBUG-65223: if only anchor changed, we never get a loadFinished signal
// If a link is clicked in a page, it can happen that the new URL has not yet been set,
// so we need to delay a bit...
QTimer::singleShot(/*magic timeout=*/150, this, [this] {
QUrl urlWithoutFragment = source();
urlWithoutFragment.setFragment(QString());
qDebug() << urlWithoutFragment << m_previousUrlWithoutFragment;
if (urlWithoutFragment == m_previousUrlWithoutFragment)
slotLoadFinished();
m_previousUrlWithoutFragment = urlWithoutFragment;
});
});
connect(m_widget, &QWebEngineView::loadFinished, this, &WebEngineHelpViewer::slotLoadFinished);
connect(m_widget, &QWebEngineView::titleChanged, this, &WebEngineHelpViewer::titleChanged);
connect(m_widget->page(), &QWebEnginePage::linkHovered, this, &WebEngineHelpViewer::setToolTip);

View File

@@ -97,6 +97,7 @@ public:
private:
WebView *m_widget;
QUrl m_previousUrlWithoutFragment;
};
} // namespace Internal