Skip to content

Commit

Permalink
fix: cannot load images under WSL2 network location
Browse files Browse the repository at this point in the history
workaround resolve GH-7
  • Loading branch information
BLumia committed Aug 28, 2020
1 parent 761f5e0 commit 9f67be6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
11 changes: 11 additions & 0 deletions graphicsview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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")) {
Expand Down
8 changes: 8 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ int main(int argc, char *argv[])
QList<QUrl> 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);
}
Expand Down

0 comments on commit 9f67be6

Please sign in to comment.