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

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

    XMLWordPrintable

Details

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

    Description

      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.

      Attachments

        Issue Links

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

          Activity

            People

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

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There are no open Gerrit changes