diff options
author | Richard Moe Gustavsen <richard.gustavsen@qt.io> | 2018-08-07 14:53:13 +0200 |
---|---|---|
committer | Richard Moe Gustavsen <richard.gustavsen@qt.io> | 2018-08-07 21:18:04 +0000 |
commit | 4853a19644aab6497953b53947e364bfdff7d285 (patch) | |
tree | 5c8535780a3222329f2be019ce13a16e837fa7eb | |
parent | 9e54a0e095e7368279c8e8d1c8d474d1bb9a2505 (diff) |
QQmlTableInstanceModel: remove false assert
There current assert turned out to not be valid for
all cases. If the model is currently incubating an
object, m_modelItems list will contain it, but
the view will not. So be more specific what we
check. Also, we need to release the object for
items that are being incubated. The code snippet
for doing that is more or less the same as found
in the destructor of QQmlDelegateModel.
Change-Id: I84b4286a037b27ad809c3a63afed94ce61febc19
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
-rw-r--r-- | src/qml/types/qqmltableinstancemodel.cpp | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/src/qml/types/qqmltableinstancemodel.cpp b/src/qml/types/qqmltableinstancemodel.cpp index 536dd46182..d667b884fc 100644 --- a/src/qml/types/qqmltableinstancemodel.cpp +++ b/src/qml/types/qqmltableinstancemodel.cpp @@ -84,14 +84,26 @@ QQmlTableInstanceModel::QQmlTableInstanceModel(QQmlContext *qmlContext, QObject QQmlTableInstanceModel::~QQmlTableInstanceModel() { - deleteAllFinishedIncubationTasks(); + for (const auto modelItem : m_modelItems) { + // No item in m_modelItems should be referenced at this point. The view + // should release all its items before it deletes this model. Only model items + // that are still being incubated should be left for us to delete. + Q_ASSERT(modelItem->objectRef == 0); + Q_ASSERT(modelItem->incubationTask); + // Check that we are not being deleted while we're + // in the process of e.g emitting a created signal. + Q_ASSERT(modelItem->scriptRef == 0); - // If we have model items loaded at this point, it means that - // the view is still holding references to them. So basically - // the view needs to be deleted first (and thereby release all - // its items), before this destructor is run. - Q_ASSERT(m_modelItems.isEmpty()); + if (modelItem->object) { + delete modelItem->object; + modelItem->object = nullptr; + modelItem->contextData->invalidate(); + modelItem->contextData = nullptr; + } + } + deleteAllFinishedIncubationTasks(); + qDeleteAll(m_modelItems); drainReusableItemsPool(0); } |