cmake-gui: Fix {begin|end}ResetModel warnings

QStandardItemModel::beginResetModel() and
QStandardItemModel::endResetModel() calls cannot be nested, and Qt will
produce warnings at runtime if such nesting is detected.

The nesting happened in two places:
1. QCMakeCacheModel::setViewType calls QCMakeCacheModel::setProperties.
Both called beginResetModel.
2. QCMakeCacheModel::setProperties calls QStandardItemModel::clear(),
which also calls beginResetModel.

The fix for 1 is to remove the {begin|end}ResetModel calls from
setViewType. The setProperties calls take care of the
{begin|end}ResetModel calls.

The fix for 2 is to replace the clear() call with a call that removes
all data rows.

Issue: #27376
This commit is contained in:
Joerg Bornemann
2025-11-11 09:18:21 +01:00
committed by Brad King
parent 86e8bd3b4b
commit 327f50083b

View File

@@ -241,7 +241,10 @@ void QCMakeCacheModel::setProperties(QCMakePropertyList const& props)
bool b = this->blockSignals(true);
this->clear();
// Empty the model. Avoid QStandardItemModel::clear(), because that calls
// beginResetModel() internally, and we can't nest such calls.
this->removeRows(0, this->rowCount());
this->NewPropertyCount = newProps.size();
if (View == FlatView) {
@@ -343,8 +346,6 @@ QCMakeCacheModel::ViewType QCMakeCacheModel::viewType() const
void QCMakeCacheModel::setViewType(QCMakeCacheModel::ViewType t)
{
this->beginResetModel();
this->View = t;
QCMakePropertyList props = this->properties();
@@ -360,7 +361,6 @@ void QCMakeCacheModel::setViewType(QCMakeCacheModel::ViewType t)
this->setProperties(oldProps);
this->setProperties(props);
this->blockSignals(b);
this->endResetModel();
}
void QCMakeCacheModel::setPropertyData(QModelIndex const& idx1,