mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2025-12-19 06:57:24 -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:
@@ -340,7 +340,7 @@ void ScanFoldersModel::makePersistent()
|
||||
|
||||
void ScanFoldersModel::configure()
|
||||
{
|
||||
QVariantHash dirs = Preferences::instance()->getScanDirs();
|
||||
const QVariantHash dirs = Preferences::instance()->getScanDirs();
|
||||
|
||||
for (QVariantHash::const_iterator i = dirs.begin(), e = dirs.end(); i != e; ++i) {
|
||||
if (i.value().type() == QVariant::Int)
|
||||
|
||||
Reference in New Issue
Block a user