开发者

Get current item from QMutableListIterator

I can't dereference a QMutableListIterator like an STL iterator - with *it.

I'm trying to use QMutableListIterator::value() but my program crashes. What is the right way to do this?

QFileInfoList files;
// populate list
QListIterator<QFileInfo> it(files);
it.toFront();
QFileInfo = it_top.value();
// crash

The error is

ASSERT: "item_exists()" in file /usr/include/qt4/QtCor开发者_JAVA技巧e/qlist.h, line 778

Thanks


I just checked the Qt documentation for "toFront" and it says:

Moves the iterator to the front of the container (before the first item).

http://doc.trolltech.com/latest/qmutablelistiterator.html#toFront

The Qt Iterators are Java-style iterators which start before the items and end on the last item, the C++ style iterators begin on the first item and end after the last one.


There is nothing wrong with the code you have shown.

The problem actually lies in // populate list

Actually I guess no item gets populated in the QFileInfoList. That's why you are getting the ASSERT when you try to access it.

And check for the hasNext() return value. Most possibly it will return false.

Hope it helps in someway..

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜