PDA

View Full Version : modifying QSet via STL iterator



tuli
11th April 2013, 08:45
I have a QSet<quint64>, and i want to add 10 to every element in the Set. Since QSetIterator<> only supports const access, i tried using an STL-style iterator.
And sure enough it works - but only for const access. If i try to write to the element, i get a compile time error:



QSet<quint64> sss;
sss << 3 << 4 << 5;

for(QSet<quint64>::iterator it=sss.begin(); it!=sss.end(); ++it)
{
*it += 10;
}


error:


Error 1 error C3892: 'it' : you cannot assign to a variable that is const


i am using winxpx86sp3, VS2008SP1+QtPlugin, Qt 484.


Any ideas?

ChrisW67
11th April 2013, 09:34
It makes no sense to modify items in a set which is why both QSet and std::set do not permit it. You can use the non-const QMutableSetIterator or STL-iterator to erase() items as described in the friendly manual.