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

Bug with QJsonArray constructor

    XMLWordPrintable

Details

    • Bug
    • Resolution: Out of scope
    • Not Evaluated
    • None
    • 6.4.3
    • Core: Item Models
    • None
    • Linux/X11

    Description

      The constructor of QJsonArray sometimes behaves very strangely. For example

      #include <QJsonArray>
      #include <QJsonDocument>
      
      class Test {
      public:
        Test(QJsonDocument jsonDocument_)
            : jsonArray{jsonDocument_.array()} {
          qDebug() << "jsonArray size = " << jsonArray.count();
        }
      
      private:
        QJsonArray jsonArray;
      };
      
      int main(int argc, char *argv[]) {
        QByteArray data = "[{}, {}]";
      
        QJsonDocument document = QJsonDocument::fromJson(data);
          qDebug() << "jsonArray size = " << document.array().count();
        Test test(document);
      }
       

      This program prints

      jsonArray size =  2
      jsonArray size =  1

      And if I changed it slightly to:

      #include <QJsonArray>
      #include <QJsonDocument>
      
      class Test {
      public:
        Test(QJsonDocument jsonDocument_)  {
          jsonArray = jsonDocument_.array();
          qDebug() << "jsonArray size = " << jsonArray.count();
        }
      
      private:
        QJsonArray jsonArray;
      };
      
      int main(int argc, char *argv[]) {
        QByteArray data = "[{}, {}]";
      
        QJsonDocument document = QJsonDocument::fromJson(data);
        qDebug() << "jsonArray size = " << document.array().count();
        Test test(document);
      }
      
      

      It works as expected.

      Attachments

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

        Activity

          People

            theartful Ahmed Essam
            theartful Ahmed Essam
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes