QMap迭代崩溃 [英] QMap iteration crash
问题描述
我在Windows 8.1上使用Qt 5.5。当我运行下面的代码,应用程序能够通过一次迭代,但崩溃的第二个。 100%可重复。 (复制/粘贴到Qt Creator实例并测试;它可能为您工作)。
I am using Qt 5.5 on Windows 8.1. When I run the code below, the application is able to get through one iteration, but crashes on the second one. 100% reproducible. (Copy/paste it into a Qt Creator instance and test; it might work for you).
#include <QCoreApplication>
#include <QDebug>
#include <utility>
using std::pair;
int main(int argc, char *argv[]) {
QCoreApplication a(argc, argv);
QMap<QString, pair<QString, QString> > table_def = {
{"alpha", {"INTEGER", "PRIMARY KEY"}},
{"beta", {"VARCHAR", ""}},
{"gamma", {"VARCHAR", ""}},
{"delta", {"REAL", "DEFAULT 0"}},
{"epsilon", {"INTEGER", ""}},
{"zeta", {"INTEGER", ""}},
{"eta", {"INTEGER", ""}},
{"theta", {"INTEGER", ""}},
{"iota", {"VARCHAR", ""}},
{"kappa", {"INTEGER", "DEFAULT 0"}},
{"lambda", {"INTEGER", "DEFAULT 0"}}
};
QMapIterator<QString, pair<QString, QString> > it(table_def);
while (it.hasNext()) {
it.next();
const QString& col_name = it.key();
qDebug() << col_name;
const QString& col_type = it.value().first;
qDebug() << col_type;
const QString& extra_def = it.value().second;
qDebug() << extra_def;
}
return a.exec();
}
我的Visual Studio调试器说:
未处理的异常在0x000000006904E394(Qt5Cored.dll)在helloqt.exe:0xC0000005:访问冲突读取位置0xFFFFFFFFFFFFFFFF。
如果它是任何相关,我在我的项目文件中添加了 DEFINES + = Q_COMPILER_INITIALIZER_LISTS
,以启用初始化列表的QContainers初始化。此外,如果我用 QPair
替换STL 对,应用程序在第一次迭代时崩溃。
If it is of any relevance, I added DEFINES += Q_COMPILER_INITIALIZER_LISTS
in my project file to enable initialization of QContainers with initializer lists. Also, if I replace the STL pair
with QPair
, the application crashes at the first iteration.
我没有看到这个代码有什么问题。
I don't see anything wrong with this code. What could be happening?
推荐答案
这是我使用的编译器版本(VS 2013)中的一个已知错误。更新Visual Studio后,这个问题消失了。
This is a known bug in the version of compiler I was using (VS 2013). After updating Visual Studio this issue went away.
这篇关于QMap迭代崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!