Results 1 to 3 of 3

Thread: Iterators v.s. index based for loops

  1. #1
    Join Date
    Oct 2010
    Posts
    41
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Iterators v.s. index based for loops

    For that reason, iterators are rarely useful in connection with QList. One place where STL-style iterators do make sense is as arguments to generic
    doc.trolltech.com/4.2/qlist-iterator.html


    So if I have a for loop, where the macro foreach isn't an option. Should I use iterators or indexes?


    Qt Code:
    1. for(int i = 0; i < list.size(); i++) {
    2. Do something with list[i]
    3. blah blah blah
    4. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. for(QList<type>::iterator i = list.begin(); i != list.end(); ++i) {
    2. Do something with *i
    3. blah blah blah
    4. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Iterators v.s. index based for loops


  3. #3
    Join Date
    Oct 2010
    Posts
    41
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Iterators v.s. index based for loops

    Thanks so much. The kind of answer I was looking for.

Similar Threads

  1. Replies: 0
    Last Post: 31st July 2010, 17:27
  2. Replies: 1
    Last Post: 24th July 2010, 17:23
  3. qDeleteAll() and linked list iterators
    By jkyle in forum Qt Programming
    Replies: 2
    Last Post: 29th June 2010, 22:18
  4. for loops in c++
    By baray98 in forum General Programming
    Replies: 16
    Last Post: 19th January 2009, 14:09
  5. QLinkedList and iterators
    By eu.x in forum Newbie
    Replies: 1
    Last Post: 19th April 2007, 19:38

Tags for this Thread

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.