summaryrefslogtreecommitdiffstats
path: root/examples/corelib/serialization/convert/jsonconverter.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Eliminate duplicate overrides of Converter methods in exampleEdward Welbourne2023-11-011-5/+0
| | | | | | | | | | | | | | | | | The Out-only converters shouldn't need to implement loadFile(), as it shouldn't be called - a converter is not used for input unless it says it supports input. At the same time, provide the "ground state" implementations for optionsHelp(), outputOptions() and probeFile() to save the trivial implementations the need to duplicate one another. In the process, make the handling of loadFile()'s outputConverter more consistent among those that do implement it. Always set outputConverter if it's initially null (the caller does assert this). Pick-to: 6.6 6.5 Task-number: QTBUG-111228 Change-Id: I856d12c791d1f8e0accdb7dd1412d493117b2302 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Replace confusing member variable with a predicateEdward Welbourne2023-11-011-1/+1
| | | | | | | | | | | | | | | | | | | The Converter class, in the eponymous example, had a null member variable that wasn't a nullptr - it pointed to an instance of NullConverter - so that other converters could test whether a Converter * they'd been passed was null (in the sense of pointing to a NullConverter). This, however, was susceptible to misreading - I misread one such comparison as a nullptr check and thus thought it redundant with an earlier actual nullptr check. To spare future readers similar confusion, replace the public static member variable with a protected (since only other derived classes need it) static predicate, to at least give the reader a clue that this is using the word null in a class-specific sense. Pick-to: 6.6 6.5 Task-number: QTBUG-111228 Change-Id: I1e4f494b303d1bf90107f8c6fa3a4a22f6d81b90 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Convert fprintf(stderr, ...); exit(EXIT_FAILURE); to qFatal(...)Edward Welbourne2023-10-301-10/+6
| | | | | | | | | | | | The serialization conversion example used raw C's way to abort on error; change to using Qt's way of doing the same. Likewise, convert the various other uses of fprintf(stderr, ...) to qWarning() and of printf(...) to qInfo(). Pick-to: 6.6 6.5 Task-number: QTBUG-111228 Change-Id: Ia8821d3c20f58f71c106028ec422ad473c11e164 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* Turn Directions enum into an enum class in serialization converterEdward Welbourne2023-09-081-1/+1
| | | | | | | | Pick-to: 6.6 6.5 Task-number: QTBUG-111228 Change-Id: Ie1f8ea5e2575427528c19875db7a8e4e27200aec Reviewed-by: Marc Mutz <marc.mutz@qt.io> Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* Turn Converter::Direction into a QFlags enumEdward Welbourne2023-09-081-1/+1
| | | | | | | | | This lets us testFlag() instead of using raw bit-field operations. Pick-to: 6.6 6.5 Task-number: QTBUG-111228 Change-Id: I2c26e9a24728e81baa42cf14c75271a015460913 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* Serialization converter example: const-ify the Converter typeEdward Welbourne2023-09-081-7/+8
| | | | | | | | | | | | Its methods act on their parameters without changing the converter, so can all be const. Its instances thus have no non-const members to exercise, so can always be const. Pick-to: 6.6 6.5 Task-number: QTBUG-111228 Change-Id: Ifcdb2f2159c2cfcd7998dd118aa327a32d299ccf Reviewed-by: Dennis Oberst <dennis.oberst@qt.io> Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* corelib/serialization examples: clang-tidy and coding style clean-upEdward Welbourne2023-09-081-6/+1
| | | | | | | | | | | | I overrode clang-tidy where it uglified or obfuscated and did some clean-up provoked or made possible by its changes. Konrad pointed out, in review, a constructor that could be = default; it could, in fact, vanish entirely as a result. Pick-to: 6.6 6.5 Task-number: QTBUG-111228 Change-Id: I9b7744a3abaa29e6f9e0689d0f6985bfd88cd0fd Reviewed-by: Konrad Kujawa <konrad.kujawa@qt.io>
* corelib/serialization examples: use string literals moreEdward Welbourne2023-09-081-4/+6
| | | | | | | | | | | | A couple more compilation units could use Qt::StringLiterals. Prefer QL1SV for the code constants, to keep code small. Convert fpToString() to take QL1SV instead of const char *, with suffix empty by default. Also rearranged some spacing, some if it suggested by clang-tidy. Pick-to: 6.6 6.5 Task-number: QTBUG-111228 Change-Id: I03d810d52afcd4a760d18f2553914b75af716b74 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
* Examples: Fix CMake Unity (Jumbo) buildsFriedemann Kleint2023-02-011-3/+4
| | | | | | | | | | Disambiguate variables and add some exclusions. Pick-to: 6.5 Task-number: QTBUG-109394 Change-Id: Ie72b3caab9fd571c3fb6f7d8606584885bc09e66 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> Reviewed-by: Amir Masoud Abdol <amir.abdol@qt.io>
* Use SPDX license identifiersLucie Gérard2022-05-161-49/+2
| | | | | | | | | | | | | Replace the current license disclaimer in files by a SPDX-License-Identifier. Files that have to be modified by hand are modified. License files are organized under LICENSES directory. Task-number: QTBUG-67283 Change-Id: Id880c92784c40f3bbde861c0d93f58151c18b9f1 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
* Deprecate QJsonDocument methods for converting to/from JSON binarySona Kurazyan2020-01-091-60/+0
| | | | | | | | | Also remove the example code for deprecated methods and use CBOR instead where it makes sense. Task-number: QTBUG-81068 Change-Id: Iffb7a4b3d7b16a1e485fc05b3ab2e2468e9e0718 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* Examples: add an example that converts between different file formatsThiago Macieira2018-07-041-0/+212
This example converts to and from: - Binary JSON - CBOR - CBOR Diagnostic notation (output only) - JSON - Null (output only) - QDataStream - QVariant dump (output only) - Text - XML Change-Id: Ibab69e0efefb40bdbf94fffd150b59f8c0da3174 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>