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:
parent
531cd052ca
commit
90cf4988ea
|
@ -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 );
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue