Results 1 to 2 of 2

Thread: modifying QSet via STL iterator

  1. #1
    Join Date
    Jul 2012
    Posts
    244
    Thanks
    27
    Thanked 15 Times in 14 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Smile modifying QSet via STL iterator

    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:


    Qt Code:
    1. QSet<quint64> sss;
    2. sss << 3 << 4 << 5;
    3.  
    4. for(QSet<quint64>::iterator it=sss.begin(); it!=sss.end(); ++it)
    5. {
    6. *it += 10;
    7. }
    To copy to clipboard, switch view to plain text mode 

    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?

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: modifying QSet via STL iterator

    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.

Similar Threads

  1. How to make a QSet hold structs?
    By wayfaerer in forum Newbie
    Replies: 2
    Last Post: 4th March 2012, 22:18
  2. QSet of QDateTime
    By Cucumber in forum Newbie
    Replies: 2
    Last Post: 21st January 2012, 02:17
  3. Using custom class as a key (QSet)
    By daujeroti in forum Qt Programming
    Replies: 4
    Last Post: 28th April 2011, 20:39
  4. QSet<QVariant> is supported ?
    By nikhilqt in forum Qt Programming
    Replies: 1
    Last Post: 4th February 2010, 07:14
  5. QSet and custom class
    By been_1990 in forum Qt Programming
    Replies: 12
    Last Post: 22nd January 2010, 16:36

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.