From 1f4b958438a7b9a7f8f3fd8139d10f5adf215a8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=99drzej=20Nowacki?= Date: Wed, 21 May 2014 16:22:49 +0200 Subject: Add initializer list support in QJsonObject. It allows to create a QJsonObject instance in C++ by using initializer list of pairs QString QJsonValue, for example: QJsonObject o = {{"property1", 1}, {"property2", 2}}; [ChangeLog][QtCore][QtJson] QJsonObject now supports C++11 initializer lists. Task-number: QTBUG-26606 Change-Id: I67af881e175f427e563e685336c48a5f8466b476 Reviewed-by: Thiago Macieira --- src/corelib/json/qjsonobject.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'src/corelib/json/qjsonobject.cpp') diff --git a/src/corelib/json/qjsonobject.cpp b/src/corelib/json/qjsonobject.cpp index 94ec9a28180..cfd797990fc 100644 --- a/src/corelib/json/qjsonobject.cpp +++ b/src/corelib/json/qjsonobject.cpp @@ -115,6 +115,20 @@ QJsonObject::QJsonObject() { } +/*! + \fn QJsonObject::QJsonObject(std::initializer_list > args) + \since 5.4 + Constructs a QJsonObject instance initialized from \a args initialization list. + For example: + \code + QJsonObject object + { + {"property1", 1}, + {"property2", 2} + }; + \endcode +*/ + /*! \internal */ @@ -126,6 +140,19 @@ QJsonObject::QJsonObject(QJsonPrivate::Data *data, QJsonPrivate::Object *object) d->ref.ref(); } +/*! + This method replaces part of the QJsonObject(std::initializer_list> args) body. + The constructor needs to be inline, but we do not want to leak implementation details + of this class. + \note this method is called for an uninitialized object + \internal + */ + +void QJsonObject::initialize() +{ + d = 0; + o = 0; +} /*! Destroys the object. -- cgit v1.2.3