From 9f67be61fbb26db3f28008d43a2898d0c73167e5 Mon Sep 17 00:00:00 2001 From: Gary Wang Date: Fri, 28 Aug 2020 13:44:41 +0800 Subject: [PATCH] fix: cannot load images under WSL2 network location workaround resolve GH-7 --- graphicsview.cpp | 11 +++++++++++ main.cpp | 8 ++++++++ 2 files changed, 19 insertions(+) diff --git a/graphicsview.cpp b/graphicsview.cpp index 5e46df6..4226ca4 100644 --- a/graphicsview.cpp +++ b/graphicsview.cpp @@ -31,6 +31,17 @@ void GraphicsView::showFileFromUrl(const QUrl &url, bool doRequestGallery) QString filePath(url.toLocalFile()); +#ifdef Q_OS_WIN + // TODO: remove this workaround when M$ change the "wsl$" hostname. + if (Q_UNLIKELY(url.scheme() == QStringLiteral("qtbug-86277"))) { + filePath = url.path(); + // Qt's QUrl won't work with such hostname anyway so the urls will + // still be the wrong one when requesting gallery. So we just don't + // request gallery here... + doRequestGallery = false; + } +#endif // Q_OS_WIN + if (filePath.endsWith(".svg")) { showSvg(filePath); } else if (filePath.endsWith(".gif")) { diff --git a/main.cpp b/main.cpp index 71da5e0..251476d 100644 --- a/main.cpp +++ b/main.cpp @@ -37,6 +37,14 @@ int main(int argc, char *argv[]) QList urlList; for (const QString & str : urlStrList) { QUrl url = QUrl::fromLocalFile(str); +#ifdef Q_OS_WIN + // TODO: remove this workaround when M$ change the "wsl$" hostname. + if (Q_UNLIKELY(str.startsWith(R"(\\wsl$\)"))) { + url.clear(); + url.setScheme(QStringLiteral("qtbug-86277")); + url.setPath(str); + } +#endif // Q_OS_WIN if (url.isValid()) { urlList.append(url); }