diff --git a/src/transferlistwidget.cpp b/src/transferlistwidget.cpp index 8e7cfe3d5..0341f2ca3 100644 --- a/src/transferlistwidget.cpp +++ b/src/transferlistwidget.cpp @@ -224,7 +224,11 @@ void TransferListWidget::setRowColor(int row, QColor color) { } void TransferListWidget::deleteTorrent(int row, bool refresh_list) { - emit torrentAboutToBeRemoved(listModel->index(row, 0)); + Q_ASSERT(row >= 0); + QModelIndex index = listModel->index(row, 0); + Q_ASSERT(index.isValid()); + if(!index.isValid()) return; + emit torrentAboutToBeRemoved(index); listModel->removeRow(row); if(refresh_list) refreshList(); @@ -299,8 +303,7 @@ int TransferListWidget::updateTorrent(int row) { QString hash = getHashFromRow(row); QTorrentHandle h = BTSession->getTorrentHandle(hash); if(!h.is_valid()) { - // Delete torrent - deleteTorrent(row, false); + // Torrent will be deleted from list by caller return s; } try { @@ -430,10 +433,9 @@ int TransferListWidget::updateTorrent(int row) { // Share ratio if(!isColumnHidden(TR_RATIO)) listModel->setData(listModel->index(row, TR_RATIO), QVariant(BTSession->getRealRatio(hash))); - }catch(invalid_handle e) { - deleteTorrent(row, false); + }catch(invalid_handle) { + // Torrent will be deleted by caller s = STATE_INVALID; - qDebug("Caught Invalid handle exception, lucky us."); } return s; } @@ -524,7 +526,9 @@ void TransferListWidget::refreshList() { } // Remove bad torrents from list foreach(QString hash, bad_hashes) { - deleteTorrent(getRowFromHash(hash), false); + int row = getRowFromHash(hash); + if(row >= 0) + deleteTorrent(row, false); } // Update status filters counters emit torrentStatusUpdate(nb_downloading, nb_seeding, nb_active, nb_inactive); @@ -970,6 +974,7 @@ void TransferListWidget::setSelectionLabel(QString label) { QModelIndexList selectedIndexes = selectionModel()->selectedRows(); foreach(const QModelIndex &index, selectedIndexes) { QString hash = getHashFromRow(mapToSource(index).row()); + Q_ASSERT(!hash.isEmpty()); QString old_label = proxyModel->data(proxyModel->index(index.row(), TR_LABEL)).toString(); proxyModel->setData(proxyModel->index(index.row(), TR_LABEL), QVariant(label)); TorrentPersistentData::saveLabel(hash, label);