summaryrefslogtreecommitdiffstats
path: root/examples/corelib/serialization/convert/main.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Rework documentation of the serialization converter exampleEdward Welbourne2023-11-011-0/+6
| | | | | | | | | | | | | | | | | | | The documentation was previously code-heavy and short on exposition, while focusing almost entirely on the CBOR converters. Prune most of the CBOR code quotes, shuffle some snippet markers, add and remove others and rewrite the main text. Shift focus to the base-class for converters and how it's used by main(). Retain relative focus on the CBOR converters, as they are relatively full-featured hence illustrate more than the others do, and replace the sequence of single-line sections about the others with a section collecting all into a table and saying some general things about them. Pick-to: 6.6 6.5 Task-number: QTBUG-111228 Change-Id: I8d41f25c165eb1a7ba20cb68aee6ab6b2fd050f8 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Move Converter class, in eponymous example, to a file of its ownEdward Welbourne2023-11-011-21/+0
| | | | | | | | | | There's more details coming and it's good hygiene anyway. Pick-to: 6.6 6.5 Task-number: QTBUG-111228 Change-Id: Ief3acf6e508bc93eaa8490f6c49300b25c1d3556 Reviewed-by: Juha Vuolle <juha.vuolle@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Break out the list of available converters to a static methodEdward Welbourne2023-11-011-10/+17
| | | | | | | | | | | | | Mostly to pave the way for moving the class code to a file of its own, but this incidentally saves the need to std::as_const() every use. Moving the underlying object to a local static of a private method also saves the need for heap allocation (which was leaked). Pick-to: 6.6 6.5 Task-number: QTBUG-111228 Change-Id: I30f4bf3c46d39e04d0ac4e3e9ba431945ebb9193 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Ville Voutilainen <ville.voutilainen@qt.io>
* Rename Convert Example to Serialization ConverterEdward Welbourne2023-10-301-3/+3
| | | | | | | | | | | | The old name didn't say what sort of thing it was converting; and our guidelines for examples discourage using the word Example in the title. Also reword the description of the tool in the command-line parser and an assertion. Pick-to: 6.6 6.5 Task-number: QTBUG-111228 Change-Id: I6f52f5227362b4b807c8aabfd2103287af42bca0 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* Convert fprintf(stderr, ...); exit(EXIT_FAILURE); to qFatal(...)Edward Welbourne2023-10-301-12/+10
| | | | | | | | | | | | 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>
* Deduplicate code in setup of serialization convertersEdward Welbourne2023-09-281-82/+49
| | | | | | | | | | | | | | | The setup of the input and output converters is fairly complex but was made harder to read by nearly-duplicating its logic for input and for output. Break out into a separate function to make clear what parts differ between the two and what parts don't. In the process, allow the search for a named converter to continue past a match that doesn't support the needed direction, on the off chance of a name collision. Make an error message more articulate in the process. Pick-to: 6.6 6.5 Task-number: QTBUG-111228 Change-Id: I2a9de8b406c538098076f388fc8a1980b91fe16b Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Check input and output converters do support the relevant directionsEdward Welbourne2023-09-151-4/+7
| | | | | | | | | | | | It was previously possible to select an input-only converter for output or an output-only converter for input. Also add a comment to explain why failure to probe for the auto output converter isn't an error, where failure to probe for the auto input converter is. Pick-to: 6.6 6.5 Task-number: QTBUG-111228 Change-Id: I17dfbbee7d8b5a9629e66d0e1a6a4014b01a7262 Reviewed-by: Ievgenii Meshcheriakov <ievgenii.meshcheriakov@qt.io>
* Turn Directions enum into an enum class in serialization converterEdward Welbourne2023-09-081-4/+6
| | | | | | | | 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-4/+4
| | | | | | | | | 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-10/+10
| | | | | | | | | | | | 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-3/+5
| | | | | | | | | | | | 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-23/+27
| | | | | | | | | | | | 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>
* Port from qAsConst() to std::as_const()Marc Mutz2022-10-111-6/+6
| | | | | | | | | | | | | | | | We've been requiring C++17 since Qt 6.0, and our qAsConst use finally starts to bother us (QTBUG-99313), so time to port away from it now. Since qAsConst has exactly the same semantics as std::as_const (down to rvalue treatment, constexpr'ness and noexcept'ness), there's really nothing more to it than a global search-and-replace, with manual unstaging of the actual definition and documentation in dist/, src/corelib/doc/ and src/corelib/global/. Task-number: QTBUG-99313 Change-Id: I4c7114444a325ad4e62d0fcbfd347d2bbfb21541 Reviewed-by: Ivan Solovev <ivan.solovev@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>
* Use QList instead of QVector in examplesJarek Kobus2020-06-231-2/+2
| | | | | | Task-number: QTBUG-84469 Change-Id: Id14119168bb1bf11f99bda7ef6ee9cf51bcfab2e Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
* Examples: add an example that converts between different file formatsThiago Macieira2018-07-041-0/+234
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>