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 <eike.ziller@qt.io>
This commit is contained in:
Jarek Kobus
2021-05-11 13:48:54 +02:00
parent 9f33f76a97
commit 671b71406b

View File

@@ -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] {