From 671b71406b61d52952cb02e3c4eda7f3a0a748ba Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Tue, 11 May 2021 13:48:54 +0200 Subject: [PATCH] Fix a crash in Find Usages Set the current index of SearchResultWindow to a valid one _before_ deleting the last SerachResultWidget inside the m_widget QStackedWidget, as this triggers the call to updateFilterButton() which uses in turn the current index of SearchResultWindow (out or range in case it's not adjusted beforehand). Fixes: QTCREATORBUG-25713 Change-Id: Ie155c5f9bacee8d647e4fa7f622ff403192cb6bc Reviewed-by: Eike Ziller --- src/plugins/coreplugin/find/searchresultwindow.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/plugins/coreplugin/find/searchresultwindow.cpp b/src/plugins/coreplugin/find/searchresultwindow.cpp index af87935623f..fb04e7b8b86 100644 --- a/src/plugins/coreplugin/find/searchresultwindow.cpp +++ b/src/plugins/coreplugin/find/searchresultwindow.cpp @@ -499,15 +499,15 @@ SearchResult *SearchResultWindow::startNewSearch(const QString &label, const QString &cfgGroup) { if (d->m_searchResults.size() >= MAX_SEARCH_HISTORY) { + if (d->m_currentIndex >= d->m_recentSearchesBox->count() - 1) { + // temporarily set the index to the last but one existing + d->m_currentIndex = d->m_recentSearchesBox->count() - 2; + } d->m_searchResultWidgets.last()->notifyVisibilityChanged(false); // widget first, because that might send interesting signals to SearchResult delete d->m_searchResultWidgets.takeLast(); delete d->m_searchResults.takeLast(); d->m_recentSearchesBox->removeItem(d->m_recentSearchesBox->count()-1); - if (d->m_currentIndex >= d->m_recentSearchesBox->count()) { - // temporarily set the index to the last existing - d->m_currentIndex = d->m_recentSearchesBox->count() - 1; - } } auto widget = new SearchResultWidget; connect(widget, &SearchResultWidget::filterInvalidated, this, [this, widget] {