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

Qt 5.12 QJsonArray is parsed differently with different compilers.

    XMLWordPrintable

Details

    • Bug
    • Resolution: Out of scope
    • Not Evaluated
    • None
    • 5.12
    • Core: Other
    • None
    • Windows 7, Windows 10, both 32 and 64 bit.
    • Windows

    Description

      On Windows systems with Qt 5.12 (various minor versions up to the most current), JSON arrays are being parsed into QJsonArray differently, depending on whether we use Qt for and with MinGW 7.3.0 or Qt for MSVC with clang-cl.

      With MSVC/clang-cl, the outcome is as one would expect: A JSON array results in a QJsonArray with one entry for each object in the array. An empty JSON array results in an empty QJsonArray.

      With MinGW, a JSON array always results in a QJsonArray with exactly one entry, which is a QJsonArray itself. That "inner" QJsonArray then contains the actual array entries (if any).

      Example code:

      static void testJsonArray()
      {
          const QByteArray jsonInput("{\"emptyArray\": []}");
      
          const QJsonDocument doc { QJsonDocument::fromJson(jsonInput) };
          const QJsonObject docObj { doc.object() };
      
          const QJsonArray emptyArray { docObj.value("emptyArray").toArray() };
      
          // MSVC/clang-cl: emptyArray is empty.
          // MinGW: emptyArray contains one subarray (!) which is empty.
          qDebug() << "empty array:" << emptyArray.count() << "entries:";
          for (const QJsonValue& e : emptyArray) {
              qDebug() << "\t" << e;
          }
      }
      

      Output with MSVC/clang-cl:

      empty array: 0 entries:
      

      Output with MinGW:

      empty array: 1 entries:
               QJsonValue(array, QJsonArray([]))
      

      Attachments

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

        Activity

          People

            thiago Thiago Macieira
            coderr Julian
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes