Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-75324

QJsonObject bug

    XMLWordPrintable

Details

    • Bug
    • Resolution: Duplicate
    • Not Evaluated
    • None
    • 5.7.0, 5.9.0, 5.11.1
    • Core: Other
    • None
    • Windows

    Description

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

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              thiago Thiago Macieira
              wxmaper aleksandr Kazantsev
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes