From 7cb307cf73c2662dac5a3e03a66fdb878d26e432 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Sun, 9 Nov 2014 21:32:38 -0800 Subject: Don't crash when restoring the selection If we end up trying to restore the selection where the selected dive is no longer visible (i.e., it's now filtered away), this code caused a crash by falling first() on an empty list. Let's not do that. Fixes #758 --- qt-ui/divelistview.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'qt-ui/divelistview.cpp') diff --git a/qt-ui/divelistview.cpp b/qt-ui/divelistview.cpp index 502cebcbd..96b9291ac 100644 --- a/qt-ui/divelistview.cpp +++ b/qt-ui/divelistview.cpp @@ -325,11 +325,13 @@ void DiveListView::selectDives(const QList &newDiveSelection) selectDive(sortedSelection.takeLast()); QSortFilterProxyModel *m = qobject_cast(model()); - QModelIndex idx = m->match(m->index(0, 0), DiveTripModel::DIVE_IDX, selected_dive, 2, Qt::MatchRecursive).first(); - if (idx.parent().isValid()) - scrollTo(idx.parent()); - scrollTo(idx); - + QModelIndexList idxList = m->match(m->index(0, 0), DiveTripModel::DIVE_IDX, selected_dive, 2, Qt::MatchRecursive); + if (!idxList.isEmpty()) { + QModelIndex idx = idxList.first(); + if (idx.parent().isValid()) + scrollTo(idx.parent()); + scrollTo(idx); + } // now that everything is up to date, update the widgets Q_EMIT currentDiveChanged(selected_dive); dontEmitDiveChangedSignal = false; -- cgit v1.2.3-70-g09d2