From ccd59b2d4f8f1c4fde3f1498d28c0dc91ba75efd Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Mon, 4 Sep 2023 14:43:02 +0200 Subject: [PATCH] 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 --- examples/corelib/serialization/convert/main.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/examples/corelib/serialization/convert/main.cpp b/examples/corelib/serialization/convert/main.cpp index 9a2720903b4..ddb5a49eed0 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