- 
    Bug 
- 
    Resolution: Duplicate
- 
     Not Evaluated Not Evaluated
- 
    None
- 
    5.7.0, 5.9.0, 5.11.1
- 
    None
I'm not sure what's bug... but this code leads to failure. Please explain 
Affects versions: Qt 5.7.0, Qt 5.9.0, Qt 5.11.1 with compilers MinGW and MSVC2015
#include <QJsonArray> #include <QJsonObject> #include <QJsonValue> #include <QDebug> class Test { public: void initLog() { QJsonObject log; log.insert("demoState", QJsonObject()); m_log = log; } void appendState(const QString &key, const QString &state) { QJsonObject demoState = m_log.value("demoState").toObject(); // Take object states by key QJsonArray states = demoState.contains(key) ? demoState.value(key).toArray() : QJsonArray(); // Add new state states.append(state); qDebug() << "states:" << states; // Update states for key demoState.insert(key, states); qDebug() << "demoState:" << demoState; m_log.insert("demoState", demoState); // <- SIGSEGV when `state == "state2"` } private: QJsonObject m_log; }; int main(int argc, char *argv[]) { Q_UNUSED(argc); Q_UNUSED(argv); Test test; test.initLog(); test.appendState("key1", "state1"); test.appendState("key2", "state1"); test.appendState("key1", "state2"); // <- Segmentation fault test.appendState("key2", "state2"); return 0; }
- relates to
- 
                    QTBUG-69626 QJsonObject memory corruption -         
- Closed
 
-