From 8126ce3fe1f7658390626ca319c93ff729373250 Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Fri, 7 Sep 2018 09:50:32 +0200 Subject: Prepend file:// on Windows when calling QJSEngine::evaluate() Due to a bug reported at QTBUG-70425, it is necessary to ensure that QJSEngine will see the filename passed in as a valid URL. So we prepend file:// for those cases to ensure qsTr() will find the right context when looking for translations. Change-Id: Ib38b1f8467de78ec82c2c6c6909487f3a06c09bb Reviewed-by: Katja Marttila --- src/libs/installer/scriptengine.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src/libs/installer/scriptengine.cpp') diff --git a/src/libs/installer/scriptengine.cpp b/src/libs/installer/scriptengine.cpp index 28f91a394..77245784c 100644 --- a/src/libs/installer/scriptengine.cpp +++ b/src/libs/installer/scriptengine.cpp @@ -396,7 +396,16 @@ QJSValue ScriptEngine::loadInContext(const QString &context, const QString &file " else" " throw \"Missing Component constructor. Please check your script.\";" "})();").arg(context); - QJSValue scriptContext = evaluate(scriptContent, fileName); + QString copiedFileName = fileName; +#ifdef Q_OS_WIN + // Workaround bug reported in QTBUG-70425 by appending "file://" when passing a filename to + // QJSEngine::evaluate() to ensure it sees it as a valid URL when qsTr() is used. + if (!copiedFileName.startsWith(QLatin1String("qrc:/")) && + !copiedFileName.startsWith(QLatin1String(":/"))) { + copiedFileName = QLatin1String("file://") + fileName; + } +#endif + QJSValue scriptContext = evaluate(scriptContent, copiedFileName); scriptContext.setProperty(QLatin1String("Uuid"), QUuid::createUuid().toString()); if (scriptContext.isError()) { throw Error(tr("Exception while loading the component script \"%1\": %2").arg( -- cgit v1.2.3