Foreach in Qt Container

Great! Qt container supports foreach iteration, which simplies largely the code. See the example for comparison:

========= java-like iterator===============
QLinkedList<> list;
QLinkedListIterator<> i(list);
while (i.hasNext())
qDebug()<< i.next()

========== STL-like iterator=============
QLinkedList<> list;
QListedList<>::const_iterator it = list.begin();
while( it!= list.end())
qDebug()<< (*it); ++it; }

=========foreach iteration===============

QLinkedList<>> list;
foreach (QString str, list)
qDebug() << str



No comments:

Post a Comment