PDA

View Full Version : QLinkedList iterator



^NyAw^
18th October 2007, 13:14
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,

marcel
18th October 2007, 13:33
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.

^NyAw^
18th October 2007, 13:35
Hi,

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

Thanks,

marcel
18th October 2007, 13:38
it exists in QLinkedList::iterator.


T & iterator::operator* () 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->().

^NyAw^
18th October 2007, 15:31
Hi,

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

Wich version of Qt are you looking?

Thanks,

marcel
18th October 2007, 15:40
http://doc.trolltech.com/4.1/qlinkedlist.html#begin
http://doc.trolltech.com/4.1/qlinkedlist-iterator.html#operator-2a

^NyAw^
18th October 2007, 16:30
Hi,

Ok, I understand how it works now.

Thanks,

^NyAw^
18th October 2007, 16:44
Hi,

I'm having problems yet.

code.h


QLinkedList<MyClass*> m_qLinkedList;
QMutableLinkedListIterator<MyClass*> m_qIterator; //The compiler don't let me do this


Any idea how to do a iterator variable?

Thanks,

^NyAw^
18th October 2007, 17:15
Hi,

I'm trying to change:


QMutableLinkedListIterator<MyClass*> m_qIterator;

for:


QLinkedList<MyClass*>::iterator m_qIterator;


In the constructor:


m_qIterator = m_qLinkedList.begin();


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

Thanks,