Properly handle removal of top level items in StandardItemIconLoader
The rowsAboutToBeRemoved signal from the model provides a parent index, but with QStandardItemModel, top level items are added to an invisible root item that doesn't have a valid index. This causes the range check to miss top level items due to a perceived parent mismatch. When the load completes, it attempts to access an object that has been deleted.
This commit is contained in:
parent
dc4270076d
commit
7e7d271b30
|
@ -60,12 +60,16 @@ void StandardItemIconLoader::LoadIcon(const Song& song,
|
|||
|
||||
void StandardItemIconLoader::RowsAboutToBeRemoved(const QModelIndex& parent,
|
||||
int begin, int end) {
|
||||
// For QStandardItemModel, the invisible root item does not have a valid index.
|
||||
bool is_top = !parent.isValid();
|
||||
|
||||
for (QMap<quint64, QStandardItem*>::iterator it = pending_covers_.begin();
|
||||
it != pending_covers_.end();) {
|
||||
const QStandardItem* item = it.value();
|
||||
const QStandardItem* item_parent = item->parent();
|
||||
|
||||
if (item_parent && item_parent->index() == parent &&
|
||||
if (((is_top && item_parent == nullptr) ||
|
||||
(item_parent != nullptr && item_parent->index() == parent)) &&
|
||||
item->index().row() >= begin && item->index().row() <= end) {
|
||||
cover_loader_->CancelTask(it.key());
|
||||
it = pending_covers_.erase(it);
|
||||
|
|
Loading…
Reference in New Issue