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

QJsonValue QJsonObject::operator[](const QString &key) const is a trap

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P3: Somewhat important P3: Somewhat important
    • None
    • 5.6.1
    • Core: Other
    • None

      The following code compiles, but it doesn't set change object because it is const:

      const QJsonObject object;
      object["foo"] = "bar";
      

      It doesn't look too harmful in the example above, but if there are just a few statements between the two statements in the example it becomes a nasty trap.

      In Qt-6, QJsonObject::operator[](const QString &) and QJsonArray::operator[](int) should return a const-ref object to eliminate this trap.

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

            Unassigned Unassigned
            ts Thomas Sondergaard
            Votes:
            2 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:

                There are no open Gerrit changes