exists = QQmlFile::bundleFileExists(qmlUrl, typeLoader->engine());
} else {
exists = !typeLoader->absoluteFilePath(QQmlFile::urlToLocalFileOrQrc(qmlUrl)).isEmpty();
+ if (!exists) {
+ QString formUrl = url + QString::fromRawData(type.constData(), type.length()) + QStringLiteral(".ui.qml");
+ if (!typeLoader->absoluteFilePath(QQmlFile::urlToLocalFileOrQrc(formUrl)).isEmpty()) {
+ exists = true;
+ qmlUrl = formUrl;
+ }
+ }
if (!exists)
exists = QQmlMetaType::findCachedCompilationUnit(QUrl(qmlUrl));
}
private slots:
void testDesignerSupported();
+ void uiFormatLoading();
void cleanup();
};
delete window;
}
+void tst_QQmlImport::uiFormatLoading()
+{
+ int size = 0;
+
+ QQmlApplicationEngine *test = new QQmlApplicationEngine(testFileUrl("TestForm.ui.qml"));
+ test->addImportPath(QT_TESTCASE_BUILDDIR);
+ QCOMPARE(test->rootObjects().size(), ++size);
+ QVERIFY(test->rootObjects()[size -1]);
+ QVERIFY(test->rootObjects()[size -1]->property("success").toBool());
+
+ QSignalSpy objectCreated(test, SIGNAL(objectCreated(QObject*,QUrl)));
+ test->load(testFileUrl("TestForm.ui.qml"));
+ QCOMPARE(objectCreated.count(), size);//one less than rootObjects().size() because we missed the first one
+ QCOMPARE(test->rootObjects().size(), ++size);
+ QVERIFY(test->rootObjects()[size -1]);
+ QVERIFY(test->rootObjects()[size -1]->property("success").toBool());
+
+ QByteArray testQml("import QtQml 2.0; QtObject{property bool success: true; property TestForm t: TestForm{}}");
+ test->loadData(testQml, testFileUrl("dynamicTestForm.ui.qml"));
+ QCOMPARE(objectCreated.count(), size);
+ QCOMPARE(test->rootObjects().size(), ++size);
+ QVERIFY(test->rootObjects()[size -1]);
+ QVERIFY(test->rootObjects()[size -1]->property("success").toBool());
+
+ test->load(testFileUrl("openTestFormFromDir.qml"));
+ QCOMPARE(objectCreated.count(), size);
+ QCOMPARE(test->rootObjects().size(), ++size);
+ QVERIFY(test->rootObjects()[size -1]);
+ QVERIFY(test->rootObjects()[size -1]->property("success").toBool());
+
+ test->load(testFileUrl("openTestFormFromQmlDir.qml"));
+ QCOMPARE(objectCreated.count(), size);
+ QCOMPARE(test->rootObjects().size(), ++size);
+ QVERIFY(test->rootObjects()[size -1]);
+ QVERIFY(test->rootObjects()[size -1]->property("success").toBool());
+
+ delete test;
+}
+
QTEST_MAIN(tst_QQmlImport)
#include "tst_qqmlimport.moc"