Fix crash when searching playlist.

While iterating over expandList in refreshExpanded, calls to setExpanded cause
the list to be appended. Since QList uses an array implementation that must
reallocate when reserved space is exhausted, iterators are unsafe for this case.
Use indexes, which are O(1) in QLists, instead of iterators.
This commit is contained in:
Jim Broadus 2020-02-23 23:20:30 -08:00 committed by John Maguire
parent 531cd052ca
commit 90cf4988ea
1 changed files with 7 additions and 1 deletions

View File

@ -67,7 +67,13 @@ class PlaylistListFilterProxyModel : public QSortFilterProxyModel {
void refreshExpanded(QTreeView *tree) {
tree->collapseAll();
for(QModelIndex sourceIndex : expandList ) {
// The call to setExpanded causes expendList to be appended via
// the filterAcceptsRow overload. Since QList's implementation is an array,
// when the reserved space is exhausted, it must be reallocated. When this
// happens, iterators are likely to break. But because of this implemention,
// indexing is safe and efficient.
for (int i = 0; i < expandList.count(); i++) {
const QModelIndex& sourceIndex = expandList[i];
QModelIndex mappedIndex = mapFromSource( sourceIndex );
tree->setExpanded( mappedIndex, true );
}