From 0d5ef23ee7cf326c080580f145123de7183dc142 Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Wed, 23 Oct 2013 15:31:10 -0700 Subject: Fix qml runtime when loading files that imported other files QQmlComponent::setData does not perform any URL processing. Consequently when using that function we need to 'normalize' the URLs ourselves to ensure that the engine finds them acceptable. Task-number: QTBUG-34301 Change-Id: Ia0f3a51129423020f7e4d7003ca356af3f89b441 Reviewed-by: Antti Piira Reviewed-by: Shawn Rutledge --- tools/qml/main.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'tools/qml') diff --git a/tools/qml/main.cpp b/tools/qml/main.cpp index 80b3d11802..4a9cad5568 100644 --- a/tools/qml/main.cpp +++ b/tools/qml/main.cpp @@ -309,14 +309,17 @@ void getAppFlags(int &argc, char **argv) } } -void getFileSansBangLine(const QString &path, QByteArray &output) +bool getFileSansBangLine(const QString &path, QByteArray &output) { QFile f(path); if (!f.open(QFile::ReadOnly | QFile::Text)) - return; + return false; output = f.readAll(); - if (output.startsWith("#!"))//Remove first line in this case (except \n, to avoid disturbing line count) + if (output.startsWith("#!")) {//Remove first line in this case (except \n, to avoid disturbing line count) output.remove(0, output.indexOf('\n')); + return true; + } + return false; } static void loadDummyDataFiles(QQmlEngine &engine, const QString& directory) @@ -479,12 +482,10 @@ int main(int argc, char *argv[]) if (!quietMode) { qDebug() << QObject::tr("qml: loading ") << path; QByteArray strippedFile; - getFileSansBangLine(path, strippedFile); - if (strippedFile.isEmpty()) - // If there's an error opening the file, this will give us the right error message + 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); - else - e.loadData(strippedFile, QUrl::fromLocalFile(path)); } else { e.load(path); } -- cgit v1.2.3