mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2025-12-21 16:07:23 -06:00
Don't implicitly cast iterator to const_iterator
It prevents detachments:
To illustrate:
QMap<QString, QString> map;
/* code compiles and works fine but find() returns the non-const
QMap::iterator that detaches!
*/
QMap<QString, QString>::const_iterator it = map.find("girish");
but also some subtle bugs:
QHash<int, int> wrong;
if (wrong.find(1) == wrong.cend()) {
qDebug() << "Not found";
} else {
/* find() detached the container before cend() was called, so it
prints "Found"
*/
qDebug() << "Found";
}
QHash<int, int> right;
if (right.constFind(1) == right.cend()) {
qDebug() << "Not found"; // This is correct now !
} else {
qDebug() << "Found";
}
Enforced by QT_STRICT_ITERATORS definition.
This commit is contained in:
@@ -66,7 +66,7 @@ void TorrentContentTreeView::keyPressEvent(QKeyEvent *event)
|
||||
Qt::CheckState state = (static_cast<Qt::CheckState>(value.toInt()) == Qt::Checked
|
||||
? Qt::Unchecked : Qt::Checked);
|
||||
|
||||
QModelIndexList selection = selectionModel()->selectedRows(TorrentContentModelItem::COL_NAME);
|
||||
const QModelIndexList selection = selectionModel()->selectedRows(TorrentContentModelItem::COL_NAME);
|
||||
|
||||
for (QModelIndexList::const_iterator i = selection.begin(); i != selection.end(); ++i) {
|
||||
QModelIndex index = *i;
|
||||
|
||||
Reference in New Issue
Block a user