From d90fb72c201efde8f9fc10c4fb4a542b1a26b9e8 Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Mon, 2 Oct 2017 08:48:05 +0200 Subject: [PATCH] Pass on local html links with a fragment to openUrl() If a file link to a html file has a fragment part included then this will be lost when passed to QDesktopServices::openUrl() as this is not kept in the conversion of the QUrl. So by checking the filename in the case of a fragment existing in the url, we can be sure that the information is passed on correctly for html files. Task-number: QTBUG-14460 Change-Id: I8167d8c164713dd999603ba9e74150f4f1a4abea Reviewed-by: David Faure --- src/gui/util/qdesktopservices.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/gui/util/qdesktopservices.cpp b/src/gui/util/qdesktopservices.cpp index 77ccc02aa5..dfd190ddd0 100644 --- a/src/gui/util/qdesktopservices.cpp +++ b/src/gui/util/qdesktopservices.cpp @@ -226,8 +226,11 @@ bool QDesktopServices::openUrl(const QUrl &url) qWarning("The platform plugin does not support services."); return false; } - return url.scheme() == QLatin1String("file") ? - platformServices->openDocument(url) : platformServices->openUrl(url); + // We only use openDocument if there is no fragment for the URL to + // avoid it being lost when using openDocument + if (url.isLocalFile() && !url.hasFragment()) + return platformServices->openDocument(url); + return platformServices->openUrl(url); } /*!