Results 1 to 9 of 9

Thread: QLinkedList iterator

  1. #1
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default QLinkedList iterator

    Hi,

    I have a QLinkedList as a variable member of a class.
    I want an iterator(mutable) variable to use it in my class methods without having to create an iterator every time. What I want is like a pointer that points the actual item.

    I'm reading about it but I'm not sure how to do it.

    Thanks,
    Òscar Llarch i Galán

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QLinkedList iterator

    Depends on which item you want.
    You have QLinkedList::begin that gives you a linked list iterator pointing to the first element.

    You can access the data with the * operator.

  3. #3
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QLinkedList iterator

    Hi,

    The operator * don't exists at QLinkedList. It exist at QList.

    Thanks,
    Òscar Llarch i Galán

  4. #4
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QLinkedList iterator

    it exists in QLinkedList::iterator.
    T & iterator:perator* () const
    Returns a modifiable reference to the current item.
    You can change the value of an item by using operator*() on the left side of an assignment, for example:
    if (*it == "Hello")
    *it = "Bonjour";
    See also operator->().

  5. #5
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QLinkedList iterator

    Hi,

    http://doc.trolltech.com/4.1/qlinkedlist.html

    Wich version of Qt are you looking?

    Thanks,
    Òscar Llarch i Galán

  6. #6
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

  7. #7
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QLinkedList iterator

    Hi,

    Ok, I understand how it works now.

    Thanks,
    Òscar Llarch i Galán

  8. #8
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QLinkedList iterator

    Hi,

    I'm having problems yet.

    code.h
    Qt Code:
    1. QLinkedList<MyClass*> m_qLinkedList;
    2. QMutableLinkedListIterator<MyClass*> m_qIterator; //The compiler don't let me do this
    To copy to clipboard, switch view to plain text mode 

    Any idea how to do a iterator variable?

    Thanks,
    Òscar Llarch i Galán

  9. #9
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QLinkedList iterator

    Hi,

    I'm trying to change:
    Qt Code:
    1. QMutableLinkedListIterator<MyClass*> m_qIterator;
    To copy to clipboard, switch view to plain text mode 
    for:
    Qt Code:
    1. QLinkedList<MyClass*>::iterator m_qIterator;
    To copy to clipboard, switch view to plain text mode 

    In the constructor:
    Qt Code:
    1. m_qIterator = m_qLinkedList.begin();
    To copy to clipboard, switch view to plain text mode 

    I don't really know if this iterator will be persistent and if I can use it to insert, remove, ...
    Will try it.

    Thanks,
    Òscar Llarch i Galán

Similar Threads

  1. QLinkedList and iterators
    By eu.x in forum Newbie
    Replies: 1
    Last Post: 19th April 2007, 19:38
  2. iterator
    By mickey in forum General Programming
    Replies: 6
    Last Post: 23rd May 2006, 10:28
  3. Std iterator as private member variable
    By Michiel in forum General Programming
    Replies: 5
    Last Post: 21st April 2006, 15:27
  4. ::iterator
    By mickey in forum General Programming
    Replies: 2
    Last Post: 20th March 2006, 22:05
  5. convert iterator
    By mickey in forum General Programming
    Replies: 8
    Last Post: 20th March 2006, 21:59

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.