@@ -142,10 +142,24 @@ Categories::roleNames() const
142 return m_roles;
142 return m_roles;
145+void Categories::onOverrideModelDestroyed()
147+ QObject* model = sender();
148+ auto iter = m_overriddenCategories.begin();
149+ while (iter != m_overriddenCategories.end()) {
150+ if (iter.value() == model) {
151+ iter = m_overriddenCategories.erase(iter);
145void Categories::overrideResults(const QString& categoryId, QAbstractItemModel* model)
158void Categories::overrideResults(const QString& categoryId, QAbstractItemModel* model)
147 m_overriddenCategories[categoryId] = model;
160 m_overriddenCategories[categoryId] = model;
148− // TODO: change the parent of the model?
161+ // watch the model
162+ connect(model, &QObject::destroyed, this, &Categories::onOverrideModelDestroyed);
149 connect(model, &QAbstractItemModel::rowsInserted, this, &Categories::onRowCountChanged);
163 connect(model, &QAbstractItemModel::rowsInserted, this, &Categories::onRowCountChanged);
150 connect(model, &QAbstractItemModel::rowsRemoved, this, &Categories::onRowCountChanged);
164 connect(model, &QAbstractItemModel::rowsRemoved, this, &Categories::onRowCountChanged);