From 6f64c84c7d51793967d7db8c79a5f82b51dcaa20 Mon Sep 17 00:00:00 2001 From: Jonathan White Date: Fri, 30 Sep 2022 09:58:11 -0400 Subject: Fix crash when application is unfocused during saves * Fix #8504 --- src/gui/DatabaseWidget.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/gui/DatabaseWidget.cpp b/src/gui/DatabaseWidget.cpp index 457dd4ec6..7f9d06fe4 100644 --- a/src/gui/DatabaseWidget.cpp +++ b/src/gui/DatabaseWidget.cpp @@ -1620,13 +1620,18 @@ bool DatabaseWidget::focusNextPrevChild(bool next) // [parent] <-> GroupView <-> TagView <-> EntryView <-> EntryPreview <-> [parent] QList sequence = {m_groupView, m_tagView, m_entryView, m_previewView}; auto widget = qApp->focusWidget(); + if (!widget) { + return QStackedWidget::focusNextPrevChild(next); + } + // Find the nearest parent widget in the sequence list int idx; do { idx = sequence.indexOf(widget); widget = widget->parentWidget(); } while (idx == -1 && widget); + // Determine next/previous or wrap around if (idx == -1) { idx = next ? 0 : sequence.size() - 1; } else { @@ -1636,7 +1641,7 @@ bool DatabaseWidget::focusNextPrevChild(bool next) // Find the next visible element in the sequence and set the focus while (idx >= 0 && idx < sequence.size()) { widget = sequence[idx]; - if (widget->isVisible() && widget->height() > 0 && widget->width() > 0) { + if (widget && widget->isVisible() && widget->height() > 0 && widget->width() > 0) { widget->setFocus(); return widget; } -- cgit v1.2.3