Details
-
Bug
-
Resolution: Out of scope
-
Not Evaluated
-
None
-
6.4.3
-
None
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.