From 05f7bcfcf032a120ef80d8e2d2fca3eafc8f643b Mon Sep 17 00:00:00 2001 From: Le Tan Date: Wed, 19 Apr 2017 20:05:28 +0800 Subject: [PATCH] bugfix: determine the base url by the file type --- src/vedittab.cpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/vedittab.cpp b/src/vedittab.cpp index c5483f3a..a1e765d7 100644 --- a/src/vedittab.cpp +++ b/src/vedittab.cpp @@ -334,7 +334,25 @@ void VEditTab::setupMarkdownPreview() if (!extraFile.isEmpty()) { htmlTemplate.replace(extraHolder, extraFile); } - webPreviewer->setHtml(htmlTemplate, QUrl::fromLocalFile(m_file->retriveBasePath() + QDir::separator())); + + // Need to judge the path: Url, local file, resource file. + QUrl baseUrl; + QString basePath = m_file->retriveBasePath(); + QFileInfo pathInfo(basePath); + if (pathInfo.exists()) { + if (pathInfo.isNativePath()) { + // Local file. + baseUrl = QUrl::fromLocalFile(basePath + QDir::separator()); + } else { + // Resource file. + baseUrl = QUrl("qrc" + basePath + QDir::separator()); + } + } else { + // Url. + baseUrl = QUrl(basePath + QDir::separator()); + } + + webPreviewer->setHtml(htmlTemplate, baseUrl); addWidget(webPreviewer); }