From 9b2b06fd7bf07e1012b47798f38ba881e693436f Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Mon, 2 Jan 2017 14:04:48 +0100 Subject: qml: use QUrl::fromUserInput("file.qml", QDir::currentPath()) After change dc6b73390b262b9554599cbf40539763b1280261 in qtbase, the qml runtime was failing at an assertion in QQmlTypeLoader::getType() which tries to avoid relative URLs and relative directory paths. It's important to convert relative paths to fully-qualified paths when converting to an URL, because QQmlTypeLoader uses it as a cache key, and we want to avoid ambiguity about which file is being cached. Task-number: QTBUG-57870 Change-Id: Ib984cf722009f5f04cb67fffbc52d12bcc98df89 Reviewed-by: David Faure Reviewed-by: Robin Burchell --- tools/qml/main.cpp | 30 +++++++----------------------- 1 file changed, 7 insertions(+), 23 deletions(-) (limited to 'tools/qml/main.cpp') diff --git a/tools/qml/main.cpp b/tools/qml/main.cpp index 5e8b872821..e8a506264c 100644 --- a/tools/qml/main.cpp +++ b/tools/qml/main.cpp @@ -46,7 +46,6 @@ #include #include #include -#include #include #include #include @@ -568,29 +567,14 @@ int main(int argc, char *argv[]) loadDummyDataFiles(e, dummyDir); for (const QString &path : qAsConst(files)) { - //QUrl::fromUserInput doesn't treat no scheme as relative file paths -#if QT_CONFIG(regularexpression) - QRegularExpression urlRe("[[:word:]]+://.*"); - if (urlRe.match(path).hasMatch()) { //Treat as a URL - QUrl url = QUrl::fromUserInput(path); - if (verboseMode) - printf("qml: loading %s\n", - qPrintable(url.isLocalFile() - ? QDir::toNativeSeparators(url.toLocalFile()) - : url.toString())); + QUrl url = QUrl::fromUserInput(path, QDir::currentPath()); + if (verboseMode) + printf("qml: loading %s\n", qPrintable(url.toString())); + QByteArray strippedFile; + if (getFileSansBangLine(path, strippedFile)) + e.loadData(strippedFile, e.baseUrl().resolved(url)); //QQmlComponent won't resolve it for us, it doesn't know it's a valid file if we loadData + else //Errors or no bang line e.load(url); - } else -#endif - { //Local file path - if (verboseMode) - printf("qml: loading %s\n", qPrintable(QDir::toNativeSeparators(path))); - - QByteArray strippedFile; - if (getFileSansBangLine(path, strippedFile)) - e.loadData(strippedFile, e.baseUrl().resolved(QUrl::fromLocalFile(path))); //QQmlComponent won't resolve it for us, it doesn't know it's a valid file if we loadData - else //Errors or no bang line - e.load(path); - } } if (lw->earlyExit) -- cgit v1.2.3