From d41bc944cce5350674a34f80ec61cc20e3adeea4 Mon Sep 17 00:00:00 2001 From: Miikka Heikkinen Date: Thu, 25 Feb 2021 15:29:40 +0200 Subject: [PATCH] Help: Fix crash with previous/next document in help mode "Previous/next Open Document in History" crashed in help mode when only a single page is open. Disable the actions in this case, and add a guard that prevents setting the current page to an invalid index. Fixes: QDS-3743 Change-Id: I569292d8c348269dd12d2ebb089c03173cbd4bc2 Reviewed-by: Eike Ziller --- src/plugins/help/helpwidget.cpp | 5 ++++- src/plugins/help/openpagesswitcher.cpp | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/plugins/help/helpwidget.cpp b/src/plugins/help/helpwidget.cpp index 65c468ac386..30a62b3381f 100644 --- a/src/plugins/help/helpwidget.cpp +++ b/src/plugins/help/helpwidget.cpp @@ -934,7 +934,10 @@ void HelpWidget::updateCloseButton() { if (supportsPages()) { const bool closeOnReturn = LocalHelpManager::returnOnClose() && m_style == ModeWidget; - m_closeAction->setEnabled(closeOnReturn || m_viewerStack->count() > 1); + const bool hasMultiplePages = m_viewerStack->count() > 1; + m_closeAction->setEnabled(closeOnReturn || hasMultiplePages); + m_gotoPrevious->setEnabled(hasMultiplePages); + m_gotoNext->setEnabled(hasMultiplePages); } } diff --git a/src/plugins/help/openpagesswitcher.cpp b/src/plugins/help/openpagesswitcher.cpp index 20117828a71..5991efd0dda 100644 --- a/src/plugins/help/openpagesswitcher.cpp +++ b/src/plugins/help/openpagesswitcher.cpp @@ -81,7 +81,9 @@ void OpenPagesSwitcher::gotoPreviousPage() void OpenPagesSwitcher::selectAndHide() { setVisible(false); - emit setCurrentPage(m_openPagesWidget->currentIndex()); + QModelIndex index = m_openPagesWidget->currentIndex(); + if (index.isValid()) + emit setCurrentPage(index); } void OpenPagesSwitcher::selectCurrentPage(int index)