Results 1 to 11 of 11

Thread: [SOLVED]Use of Iterator to access a QList

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2008
    Location
    Portugal
    Posts
    171
    Thanks
    57
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default [SOLVED]Use of Iterator to access a QList

    Hi,
    Here is the code:
    Qt Code:
    1. #include <QDebug>
    2. #include <QList>
    3.  
    4. class Node
    5. {
    6. public:
    7. int a;
    8. int b;
    9. };
    10. int main(int argc, char *argv[])
    11. {
    12. //case1
    13. QList<int> list1;
    14. list1.append(10);
    15. list1.append(3);
    16. QList<int>::iterator i;
    17. for (i = list1.begin(); i != list1.end(); ++i)
    18. qDebug() << *i;
    19.  
    20. //case2
    21. QList<Node> list2;
    22. Node no = {10, 3};
    23. list2.append(no);
    24. QList<Node>::iterator j;
    25. for (j = list2.begin(); j != list2.end(); ++j)
    26. //here ???
    27. ;
    28.  
    29. }
    To copy to clipboard, switch view to plain text mode 
    In case 2, how can i access the a and b from each node?
    Thanks
    Last edited by graciano; 22nd March 2010 at 16:06.

Similar Threads

  1. segfault while trying to access QList
    By Raven24 in forum General Programming
    Replies: 1
    Last Post: 3rd March 2010, 06:53
  2. pointer and iterator
    By mickey in forum General Programming
    Replies: 6
    Last Post: 3rd February 2008, 22:24
  3. QLinkedList iterator
    By ^NyAw^ in forum Qt Programming
    Replies: 8
    Last Post: 18th October 2007, 16:15
  4. iterator
    By mickey in forum General Programming
    Replies: 6
    Last Post: 23rd May 2006, 10:28
  5. ::iterator
    By mickey in forum General Programming
    Replies: 2
    Last Post: 20th March 2006, 22:05

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
  •  
Qt is a trademark of The Qt Company.