aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2017-09-25 17:50:33 +0200
committerUlf Hermann <ulf.hermann@qt.io>2017-10-20 13:06:56 +0000
commitebceda0cad6d86f6d6fe5efbf85a3b06fb4222b0 (patch)
treeebeda6541a2b114c21016a1499ceed7f8bb56e1f /tests
parent5a979e2d24b51e931a158062d322d0340e666bff (diff)
QQmlTypeLoader: Drain events before shutting down the thread
We take references to types when sending events to the other thread. If we don't process the events, the references are kept, which leads to memory leaks. Therefore, when shutting down a QML engine, we have to make sure the event queues are emptied. Change-Id: Id8b0440029cfd7d03a9e540747eaedbcaa7c9ff3 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qml/qqmltypeloader/data/Fast/Fast.qml4
-rw-r--r--tests/auto/qml/qqmltypeloader/data/Fast/qmldir1
-rw-r--r--tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.cpp47
3 files changed, 52 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmltypeloader/data/Fast/Fast.qml b/tests/auto/qml/qqmltypeloader/data/Fast/Fast.qml
new file mode 100644
index 0000000000..e879577e10
--- /dev/null
+++ b/tests/auto/qml/qqmltypeloader/data/Fast/Fast.qml
@@ -0,0 +1,4 @@
+import QtQml 2.0
+
+QtObject {
+}
diff --git a/tests/auto/qml/qqmltypeloader/data/Fast/qmldir b/tests/auto/qml/qqmltypeloader/data/Fast/qmldir
new file mode 100644
index 0000000000..a6a4c9e6c7
--- /dev/null
+++ b/tests/auto/qml/qqmltypeloader/data/Fast/qmldir
@@ -0,0 +1 @@
+Fast 1.0 Fast.qml
diff --git a/tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.cpp b/tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.cpp
index 24f3cbc20d..68b450ab26 100644
--- a/tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.cpp
+++ b/tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.cpp
@@ -44,6 +44,7 @@ private slots:
void trimCache();
void trimCache2();
void keepSingleton();
+ void keepRegistrations();
};
void tst_QQMLTypeLoader::testLoadComplete()
@@ -145,6 +146,52 @@ void tst_QQMLTypeLoader::keepSingleton()
checkSingleton(dataDirectory());
}
+class TestObject : public QObject
+{
+ Q_OBJECT
+public:
+ TestObject(QObject *parent = 0) : QObject(parent) {}
+};
+
+QML_DECLARE_TYPE(TestObject)
+
+static void verifyTypes(bool shouldHaveTestObject, bool shouldHaveFast)
+{
+ bool hasTestObject = false;
+ bool hasFast = false;
+ for (const QQmlType &type : QQmlMetaType::qmlAllTypes()) {
+ if (type.elementName() == QLatin1String("Fast"))
+ hasFast = true;
+ else if (type.elementName() == QLatin1String("TestObject"))
+ hasTestObject = true;
+ }
+ QCOMPARE(hasTestObject, shouldHaveTestObject);
+ QCOMPARE(hasFast, shouldHaveFast);
+}
+
+void tst_QQMLTypeLoader::keepRegistrations()
+{
+ verifyTypes(false, false);
+ qmlRegisterType<TestObject>("Test", 1, 0, "TestObject");
+ verifyTypes(true, false);
+
+ {
+ QQmlEngine engine;
+ engine.addImportPath(dataDirectory());
+ QQmlComponent component(&engine);
+ component.setData("import Fast 1.0\nFast {}", QUrl());
+ QVERIFY2(component.errorString().isEmpty(), component.errorString().toUtf8().constData());
+ QCOMPARE(component.status(), QQmlComponent::Ready);
+ QScopedPointer<QObject> o(component.create());
+ QVERIFY(o.data());
+ verifyTypes(true, true);
+ }
+
+ verifyTypes(true, false); // Fast is gone again, even though an event was still scheduled.
+ QQmlMetaType::freeUnusedTypesAndCaches();
+ verifyTypes(true, false); // qmlRegisterType creates an undeletable type.
+}
+
QTEST_MAIN(tst_QQMLTypeLoader)
#include "tst_qqmltypeloader.moc"