c++ - 从 QMutableListIterator 获取当前项

标签 c++ qt

我不能像 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/

相关文章:

c++ - 如何在 Linux 上使用 polkit 请求串口权限?

c++ - QVector<int>[index] 返回另一个 QVector?

c++ - VTK 示例不工作 - QVTKOpenGLWidget?

c++ - 要在 scanf() 的扫描集中包含一个连字符作为元素,它应该是列表中的第一个字符还是最后一个字符?

c++ - 错误 : No Matching Constructor when trying to construct a templated object from a vector value

c++ - 从当前打开 QWidget 或 QWindow

python - MySQL返回的数据类型和python为不同的函数输出不同的类型

c++ - 如何在访问者模式的节点上存储状态?

c++ - wintun:注册环形缓冲区时出现ERROR_INVALID_PARAMETER

c++ - Arduino:无法将取消引用的指针值从库函数返回到草图