Commit ff19cee1 authored by Ingo Klöcker's avatar Ingo Klöcker
Browse files

Prevent a crash caused by a stale model index

While the EditGroupDialog is open the model may be updated (e.g.
because the Tags column is enabled in the EditGroupDialog but not in
the main view). This will invalidate the group index. Get a fresh index
by looking up the index of the updated group in the model.

GnuPG-bug-id: 5638
parent 96da1081
......@@ -144,6 +144,15 @@ public:
auto getGroupIndex(const KeyGroup &group)
QModelIndex index;
if (const KeyListModelInterface *const klmi = dynamic_cast<KeyListModelInterface *>(ui.groupsList->model())) {
index = klmi->index(group);
return index;
auto selectedRows()
return ui.groupsList->selectionModel()->selectedRows();
......@@ -244,7 +253,13 @@ private:
const bool success = ui.groupsList->model()->setData(groupIndex, QVariant::fromValue(updatedGroup));
// look up index of updated group; the groupIndex used above may have become invalid
const auto updatedGroupIndex = getGroupIndex(updatedGroup);
if (!updatedGroupIndex.isValid()) {
qCDebug(KLEOPATRA_LOG) << __func__ << "Failed to find index of group" << updatedGroup;
const bool success = ui.groupsList->model()->setData(updatedGroupIndex, QVariant::fromValue(updatedGroup));
if (!success) {
qCDebug(KLEOPATRA_LOG) << "Updating group in model failed";
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment