diff options
author | Edward Welbourne <edward.welbourne@qt.io> | 2023-09-04 14:43:02 +0200 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@qt.io> | 2023-09-15 21:53:36 +0200 |
commit | ccd59b2d4f8f1c4fde3f1498d28c0dc91ba75efd (patch) | |
tree | 62a49dfc27653f26456167184a18d4b34011d09b /examples/corelib/serialization | |
parent | b9787a3985e503a51115da6a7282eb27f1958c64 (diff) |
Check input and output converters do support the relevant directions
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>
Diffstat (limited to 'examples/corelib/serialization')
-rw-r--r-- | examples/corelib/serialization/convert/main.cpp | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/examples/corelib/serialization/convert/main.cpp b/examples/corelib/serialization/convert/main.cpp index 9a2720903b..ddb5a49eed 100644 --- a/examples/corelib/serialization/convert/main.cpp +++ b/examples/corelib/serialization/convert/main.cpp @@ -113,8 +113,9 @@ int main(int argc, char *argv[]) } } - if (!inconv) { - fprintf(stderr, "Unknown file format \"%s\"\n", qPrintable(format)); + if (!inconv || !inconv->directions().testFlag(Converter::Direction::In)) { + fprintf(stderr, inconv ? "File format \"%s\" cannot be used for input\n" + : "Unknown input file format \"%s\"\n", qPrintable(format)); return EXIT_FAILURE; } } @@ -129,8 +130,9 @@ int main(int argc, char *argv[]) } } - if (!outconv) { - fprintf(stderr, "Unknown file format \"%s\"\n", qPrintable(format)); + if (!outconv || !outconv->directions().testFlag(Converter::Direction::Out)) { + fprintf(stderr, outconv ? "File format \"%s\" cannot be used for output\n" + : "Unknown output file format \"%s\"\n", qPrintable(format)); return EXIT_FAILURE; } } @@ -184,6 +186,7 @@ int main(int argc, char *argv[]) break; } } + // If that failed, loadFile() shall supply a fallback. } // now finally perform the conversion |