Editable QSqlQueryModel closeEditor message
-
Hey all,
I'm getting "QAbstractItemView::closeEditor called with an editor that does not belong to this view" logged to the Application Output console when editing cells in Editable Query Model Example.
I believe the issue is that the model is being reset before the delegate has had time properly cleanup based on the placement of "clear()" and "refresh()" within the setData method below.
I've tried layering in the traditional model/view signals (beginResetModel, dataChanged, etc.) but must be missing something.
The functionality is working fine, but want to have a better understanding of why this message is generating to fix in my application.
bool EditableSqlModel::setData(const QModelIndex &index, const QVariant &value, int /* role */) { if (index.column() < 1 || index.column() > 2) return false; QModelIndex primaryKeyIndex = QSqlQueryModel::index(index.row(), 0); int id = data(primaryKeyIndex).toInt(); clear(); bool ok; if (index.column() == 1) { ok = setFirstName(id, value.toString()); } else { ok = setLastName(id, value.toString()); } refresh(); return ok; }
-
Hey all,
I'm getting "QAbstractItemView::closeEditor called with an editor that does not belong to this view" logged to the Application Output console when editing cells in Editable Query Model Example.
I believe the issue is that the model is being reset before the delegate has had time properly cleanup based on the placement of "clear()" and "refresh()" within the setData method below.
I've tried layering in the traditional model/view signals (beginResetModel, dataChanged, etc.) but must be missing something.
The functionality is working fine, but want to have a better understanding of why this message is generating to fix in my application.
bool EditableSqlModel::setData(const QModelIndex &index, const QVariant &value, int /* role */) { if (index.column() < 1 || index.column() > 2) return false; QModelIndex primaryKeyIndex = QSqlQueryModel::index(index.row(), 0); int id = data(primaryKeyIndex).toInt(); clear(); bool ok; if (index.column() == 1) { ok = setFirstName(id, value.toString()); } else { ok = setLastName(id, value.toString()); } refresh(); return ok; }
@ZNohre I've had the same problem with my programs for years. They function just fine, but I'd like to better understand what's going on. Did you make any progress with this?
-
@ZNohre I've had the same problem with my programs for years. They function just fine, but I'd like to better understand what's going on. Did you make any progress with this?
@mjsmithers
Just in case, I'd change that sample code not to ignorerole
parameter. It should only do what it does ifQt::EditRole
.Then I see it has 3 views. Does this occur on all of them?
I agree: it seems to me
clear()
ing the model when your are editing an item in an attached view is not a good idea, if that is the cause of the message. Comment out theclear()
? -
@ZNohre Such an error can appear when the same item delegate is used in multiple views.