diff options
author | Andy Shaw <andy.shaw@qt.io> | 2018-09-07 09:50:32 +0200 |
---|---|---|
committer | Katja Marttila <katja.marttila@qt.io> | 2018-09-10 04:50:10 +0000 |
commit | 8126ce3fe1f7658390626ca319c93ff729373250 (patch) | |
tree | 688ac14acb93164b1521082e64814b0da121ebb9 | |
parent | 81bc4da588a8950a2c2e3cd3c47b793e46d19bea (diff) |
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 <katja.marttila@qt.io>
-rw-r--r-- | src/libs/installer/scriptengine.cpp | 11 |
1 files changed, 10 insertions, 1 deletions
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( |