From eef8741b4bdb3427662c1cbedb054eb0ed8fc94a Mon Sep 17 00:00:00 2001 From: nowrep Date: Sat, 8 Feb 2014 00:19:22 +0100 Subject: [PATCH] [QJson] Hack to check for Indent support There is no library version available in header files, so this is the only solution to fix building on Debian stable --- src/defines.pri | 3 +++ src/lib/tools/json.cpp | 10 +++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/defines.pri b/src/defines.pri index 4755adf24..ab1e00747 100644 --- a/src/defines.pri +++ b/src/defines.pri @@ -58,6 +58,9 @@ else { } } +# Ugly hack to check for Indent support in QJson +system(grep "enum IndentMode" /usr/include/qjson/serializer.h &> /dev/null): DEFINES *= QJSON_HAVE_INDENT + DEFINES *= QT_NO_URL_CAST_FROM_STRING DEFINES *= QT_USE_QSTRINGBUILDER diff --git a/src/lib/tools/json.cpp b/src/lib/tools/json.cpp index 357627548..8ffe1f379 100644 --- a/src/lib/tools/json.cpp +++ b/src/lib/tools/json.cpp @@ -45,8 +45,16 @@ QByteArray Json::serialize(const QVariant &variant, bool* ok) { #if QT_VERSION < 0x050000 QJson::Serializer serializer; +#ifdef QJSON_HAVE_INDENT serializer.setIndentMode(QJson::IndentFull); - return serializer.serialize(variant, ok); +#endif + const QByteArray data = serializer.serialize(variant); + + if (ok) { + *ok = !data.isNull(); + } + + return data; #else QJsonDocument doc = QJsonDocument::fromVariant(variant);