summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMike Krus <mike.krus@kdab.com>2019-05-08 19:23:15 +0100
committerMike Krus <mike.krus@kdab.com>2019-05-28 14:22:32 +0100
commit50d41e6f0e7dd97f3d4cbd68423d59cacd4b7700 (patch)
tree72e10837382c709163ba10aaff07ef1967b0fdf9 /tests
parent2cdd87235fd86d9f2c0e8500be8d429b4f85b64a (diff)
Fix removal of components when they are destroyed
Automatic removal of components when they are destroyed is based on connecting to the destroyed() signal. This however means that by the time removeComponent() is called, the pointer is no longer a valid QComponent (just a QNode). While accessing member data of derived classes such as nodeId is fine, emitting signals from derived class does nothing, and in some cases asserts. Fix this by: - doing the QComponent clean up from it's destructor - implementing a separate method on QEntity to simply clear the now partly invalid pointer from the list. Change-Id: Id7632ee2ceaff6548c44c7a43ae40a0372febde9 Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/core/qentity/tst_qentity.cpp11
1 files changed, 10 insertions, 1 deletions
diff --git a/tests/auto/core/qentity/tst_qentity.cpp b/tests/auto/core/qentity/tst_qentity.cpp
index ef520d7f2..bc0707f05 100644
--- a/tests/auto/core/qentity/tst_qentity.cpp
+++ b/tests/auto/core/qentity/tst_qentity.cpp
@@ -655,10 +655,19 @@ void tst_Entity::checkComponentBookkeeping()
QCOMPARE(rootEntity->components().size(), 1);
// WHEN
- rootEntity.reset();
+ int sigCount = 0;
+ QObject *sigSender = comp.data();
+ connect(comp.data(), &QComponent::removedFromEntity, [&sigCount, sigSender](QEntity *) {
+ QComponent *c = qobject_cast<QComponent *>(sigSender);
+ if (sigSender && c)
+ sigCount++; // test the sender is still a QComponent when signal is emitted
+ });
+
comp.reset();
+ rootEntity.reset();
// THEN (Should not crash when the comp is destroyed (tests for failed removal of destruction helper)
+ QCOMPARE(sigCount, 1);
}
}