问题描述
最近遇到一个bug, 关于嵌套调用QMap迭代器,大循环只循环一次,crash信息提示停在`iterator::operator++
Qt5Cored.dll!QMapNodeBase::nextNode() Line 89 C++
demo64.exe!QMapNode<__int64,QString>::nextNode() Line 117 C++
demo64.exe!QMap<__int64,QString>::iterator::operator++() Line 426 C++
demo64.exe!demo64::demo64(QWidget * parent) Line 15 C++
`
代码抽象出来如下:
cpp文件:
#include "demo64.h"
#include<QtDebug>
demo64::demo64()
{
_info.clear();
_info.insert(1, "Monday");
_info.insert(2, "Tuesday");
QMap<qint64, QString>::iterator itt;
for (itt = _info.begin(); itt != _info.end(); ++itt) // 执行到第二次时crash
{
qDebug() << "value addr=" << &(itt.value());
QMap<qint64, QString> info = _info; // 关键
QMap<qint64, QString>::iterator it;
for (it = _info.begin(); it != _info.end(); ++it)
{
qDebug() << "value addr2=" <&l