Changeset View
Changeset View
Standalone View
Standalone View
ktorrent/tools/queuemanagermodel.cpp
Show First 20 Lines • Show All 131 Lines • ▼ Show 20 Line(s) | 41 | { | |||
---|---|---|---|---|---|
132 | { | 132 | { | ||
133 | connect(tc, &bt::TorrentInterface::statusChanged, this, &QueueManagerModel::onTorrentStatusChanged); | 133 | connect(tc, &bt::TorrentInterface::statusChanged, this, &QueueManagerModel::onTorrentStatusChanged); | ||
134 | } | 134 | } | ||
135 | 135 | | |||
136 | void QueueManagerModel::onTorrentRemoved(bt::TorrentInterface* tc) | 136 | void QueueManagerModel::onTorrentRemoved(bt::TorrentInterface* tc) | ||
137 | { | 137 | { | ||
138 | disconnect(tc, SIGNAL(statusChanged(bt::TorrentInterface*)), | 138 | disconnect(tc, SIGNAL(statusChanged(bt::TorrentInterface*)), | ||
139 | this, SLOT(onTorrentStatusChanged(bt::TorrentInterface*))); | 139 | this, SLOT(onTorrentStatusChanged(bt::TorrentInterface*))); | ||
140 | int r = 0; | ||||
141 | const auto queueCopy = queue; | ||||
142 | | ||||
stikonas: I am a bit reluctant to use foreach in new code.
Firstly, of all they are discouraged (https… | |||||
This might result in undefined behaviour. You are iterating over a container that is being modified. You need to take a copy here stikonas: This might result in undefined behaviour. You are iterating over a container that is being… | |||||
143 | for (const auto &i : queueCopy) | ||||
144 | { | ||||
145 | if (tc == i.tc) | ||||
146 | { | ||||
147 | queue.removeAt(r); | ||||
148 | removeRow(r); | ||||
149 | break; | ||||
150 | } | ||||
151 | r++; | ||||
152 | } | ||||
I'm getting
while git apply the diff bcs of this line. Could you fix? trufanov: I'm getting
> /tmp/D25680.diff:20: trailing whitespace.
>
> warning: 1 line adds… | |||||
153 | | ||||
140 | } | 154 | } | ||
141 | 155 | | |||
142 | void QueueManagerModel::onTorrentStatusChanged(bt::TorrentInterface* tc) | 156 | void QueueManagerModel::onTorrentStatusChanged(bt::TorrentInterface* tc) | ||
143 | { | 157 | { | ||
144 | int r = 0; | 158 | int r = 0; | ||
145 | foreach (const Item& i, queue) | 159 | foreach (const Item& i, queue) | ||
146 | { | 160 | { | ||
147 | if (tc == i.tc) | 161 | if (tc == i.tc) | ||
▲ Show 20 Lines • Show All 423 Lines • Show Last 20 Lines |
I am a bit reluctant to use foreach in new code.
Firstly, of all they are discouraged (https://www.kdab.com/goodbye-q_foreach/), secondly, you have to introduce index variable r anyway.
On the other hand it's very similar code to the code in other parts of this file...
Other than that, it looks alright.