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 <apiira@blackberry.com> Reviewed-by: Shawn Rutledge <shawn.rutledge@digia.com>
This commit is contained in:
parent
6ecf0f00dd
commit
0d5ef23ee7
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue