我不能像 STL 迭代器那样取消引用 QMutableListIterator - 使用 *it。
我正在尝试使用 QMutableListIterator::value() 但我的程序崩溃了。执行此操作的正确方法是什么?
QFileInfoList files;
// populate list
QListIterator<QFileInfo> it(files);
it.toFront();
QFileInfo = it_top.value();
// crash
错误是
ASSERT: "item_exists()" in file /usr/include/qt4/QtCore/qlist.h, line 778
谢谢
最佳答案
我刚刚检查了“toFront”的 Qt 文档,它说:
Moves the iterator to the front of the container (before the first item).
http://doc.trolltech.com/latest/qmutablelistiterator.html#toFront
Qt 迭代器是 Java 风格的迭代器,它在项目之前开始并在最后一个项目结束,C++ 风格的迭代器在第一个项目开始并在最后一个项目之后结束。
关于c++ - 从 QMutableListIterator 获取当前项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3466984/