diff options
author | Erik Larsson <[email protected]> | 2014-03-01 07:28:29 +0100 |
---|---|---|
committer | The Qt Project <[email protected]> | 2014-03-13 21:40:43 +0100 |
commit | f3d8386bcd784c2693d0fcc10f9b621de80f7ae0 (patch) | |
tree | 54e76f2ed1acf7310683004cfd7c32167f5a582a | |
parent | 5e75ee31289accc1c1ae266b331ccb094319dbf0 (diff) |
Fix crash in qml/qmlscene when using dummy-data with imports
When using the tools qml and qmlscene with dummy-data it will crash or
behave wrong, due to the dummy-data component will get the state not
ready, if the dummy-data qml-files does an import of another folder or
a js-file. By changing the way of loading dummy-data, by letting
QQmlComponent handle the file opening instead of using the setData()
method, qmlscene and qml will be able to handle this type of
dummy-data.
The tool qml also needed to load the dummy data before loading the
regular components, otherwise the dummy-data would not be ready for the
other components to use.
Task-number: QTBUG-32721
Change-Id: Ia1cc2b2626187e23c7d7313be788202d91b12471
Reviewed-by: Alan Alpert <[email protected]>
-rw-r--r-- | tools/qml/main.cpp | 14 | ||||
-rw-r--r-- | tools/qmlscene/main.cpp | 6 |
2 files changed, 6 insertions, 14 deletions
diff --git a/tools/qml/main.cpp b/tools/qml/main.cpp index 08095962be..3fa36ad8f7 100644 --- a/tools/qml/main.cpp +++ b/tools/qml/main.cpp @@ -351,11 +351,7 @@ static void loadDummyDataFiles(QQmlEngine &engine, const QString& directory) QStringList list = dir.entryList(); for (int i = 0; i < list.size(); ++i) { QString qml = list.at(i); - QFile f(dir.filePath(qml)); - f.open(QIODevice::ReadOnly); - QByteArray data = f.readAll(); - QQmlComponent comp(&engine); - comp.setData(data, QUrl()); + QQmlComponent comp(&engine, dir.filePath(qml)); QObject *dummyData = comp.create(); if (comp.isError()) { @@ -500,6 +496,10 @@ int main(int argc, char *argv[]) //Load files LoadWatcher lw(&e, files.count()); + // Load dummy data before loading QML-files + if (!dummyDir.isEmpty() && QFileInfo (dummyDir).isDir()) + loadDummyDataFiles(e, dummyDir); + foreach (const QString &path, files) { //QUrl::fromUserInput doesn't treat no scheme as relative file paths QRegularExpression urlRe("[[:word:]]+://.*"); @@ -523,10 +523,6 @@ int main(int argc, char *argv[]) } } - - if (!dummyDir.isEmpty() && QFileInfo (dummyDir).isDir()) - loadDummyDataFiles(e, dummyDir); - return app->exec(); } diff --git a/tools/qmlscene/main.cpp b/tools/qmlscene/main.cpp index fcf89afb9f..531c894ada 100644 --- a/tools/qmlscene/main.cpp +++ b/tools/qmlscene/main.cpp @@ -323,11 +323,7 @@ static void loadDummyDataFiles(QQmlEngine &engine, const QString& directory) QStringList list = dir.entryList(); for (int i = 0; i < list.size(); ++i) { QString qml = list.at(i); - QFile f(dir.filePath(qml)); - f.open(QIODevice::ReadOnly); - QByteArray data = f.readAll(); - QQmlComponent comp(&engine); - comp.setData(data, QUrl()); + QQmlComponent comp(&engine, dir.filePath(qml)); QObject *dummyData = comp.create(); if(comp.isError()) { |