QMap iteration crash

自闭症网瘾萝莉.ら 提交于 2019-12-23 03:03:44

问题


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();
}

My Visual Studio debugger says: Unhandled exception at 0x000000006904E394 (Qt5Cored.dll) in helloqt.exe: 0xC0000005: Access violation reading location 0xFFFFFFFFFFFFFFFF.

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?


回答1:


This is a known bug in the version of compiler I was using (VS 2013). After updating Visual Studio this issue went away.



来源:https://stackoverflow.com/questions/31420407/qmap-iteration-crash

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!