diff options
author | Øystein Heskestad <oystein.heskestad@qt.io> | 2023-03-01 14:23:45 +0100 |
---|---|---|
committer | Øystein Heskestad <oystein.heskestad@qt.io> | 2023-03-02 12:20:18 +0100 |
commit | e13b57d06ab6e81cf04c090cc46dd23b4f8daccf (patch) | |
tree | 2964cabd09607f6b8d0c62d55f791f4ba73963fc /examples/xml | |
parent | 56b3123689be7c408d9b6c8c48648a15f0e46658 (diff) |
Move xmlstreamlint example into tests/manual
This example is useful but not a typical starting point for an
application.
Task-number: QTBUG-110647
Pick-to: 6.5
Change-Id: Ic4af8ed648c587b91110a7403fa80c619549289d
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Diffstat (limited to 'examples/xml')
-rw-r--r-- | examples/xml/CMakeLists.txt | 1 | ||||
-rw-r--r-- | examples/xml/xml.pro | 1 | ||||
-rw-r--r-- | examples/xml/xmlstreamlint/CMakeLists.txt | 35 | ||||
-rw-r--r-- | examples/xml/xmlstreamlint/doc/src/xmlstreamlint.qdoc | 51 | ||||
-rw-r--r-- | examples/xml/xmlstreamlint/main.cpp | 90 | ||||
-rw-r--r-- | examples/xml/xmlstreamlint/xmlstreamlint.pro | 7 |
6 files changed, 0 insertions, 185 deletions
diff --git a/examples/xml/CMakeLists.txt b/examples/xml/CMakeLists.txt index 2ff2984a6c..6864435951 100644 --- a/examples/xml/CMakeLists.txt +++ b/examples/xml/CMakeLists.txt @@ -1,7 +1,6 @@ # Copyright (C) 2022 The Qt Company Ltd. # SPDX-License-Identifier: BSD-3-Clause -qt_internal_add_example(xmlstreamlint) if(TARGET Qt6::Widgets) qt_internal_add_example(dombookmarks) qt_internal_add_example(streambookmarks) diff --git a/examples/xml/xml.pro b/examples/xml/xml.pro index 1c78e6b570..4a2caa1648 100644 --- a/examples/xml/xml.pro +++ b/examples/xml/xml.pro @@ -1,5 +1,4 @@ TEMPLATE = subdirs -SUBDIRS = xmlstreamlint qtHaveModule(widgets) { SUBDIRS += dombookmarks \ diff --git a/examples/xml/xmlstreamlint/CMakeLists.txt b/examples/xml/xmlstreamlint/CMakeLists.txt deleted file mode 100644 index 1feee1a1c2..0000000000 --- a/examples/xml/xmlstreamlint/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -# Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: BSD-3-Clause - -cmake_minimum_required(VERSION 3.16) -project(xmlstreamlint LANGUAGES CXX) - -if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") -endif() - -set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/xml/xmlstreamlint") - -find_package(Qt6 REQUIRED COMPONENTS Core Xml) - -qt_standard_project_setup() - -qt_add_executable(xmlstreamlint - main.cpp -) - -set_target_properties(xmlstreamlint PROPERTIES - WIN32_EXECUTABLE FALSE - MACOSX_BUNDLE FALSE -) - -target_link_libraries(xmlstreamlint PRIVATE - Qt6::Core - Qt6::Xml -) - -install(TARGETS xmlstreamlint - RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" - BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" - LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" -) diff --git a/examples/xml/xmlstreamlint/doc/src/xmlstreamlint.qdoc b/examples/xml/xmlstreamlint/doc/src/xmlstreamlint.qdoc deleted file mode 100644 index 870203c584..0000000000 --- a/examples/xml/xmlstreamlint/doc/src/xmlstreamlint.qdoc +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only - -/*! - \example xmlstreamlint - \title XML Stream Lint Example - \ingroup xml-examples - \brief A commandline tool reading from an input file and writing to - the standard output file. - - The XML Stream Lint example provides a simple command line utility that - accepts a file name as its single argument and writes it to the standard - output file. - - The specified file is parsed using an QXmlStreamReader object and written - to the standard output file using an QXmlStreamWriter object. If the file - does not contain a well-formed XML document or the use of namespaces in - the document is incorrect, a description of the error is printed to - the standard error file and will appear in the console. - - \section1 Basic Operation - - The main function of the example opens the file specified by the user - for input (\c inputFile), and it uses QFile to access the standard output - file. - - Reading XML is handled by an instance of the QXmlStreamReader class, which - operates on the input file object; writing is handled by an instance of - QXmlStreamWriter operating on the output file object: - - \snippet xmlstreamlint/main.cpp 0 - - The work of parsing and rewriting the XML is done in a while loop, and is - driven by input from the reader: - - \snippet xmlstreamlint/main.cpp 1 - - If more input is available, the next token from the input file is read - and parsed. If an error occurred, information is written to the standard - error file via a stream, and the example exits by returning a non-zero - value from the main function. - - \snippet xmlstreamlint/main.cpp 2 - - For valid input, the writer is fed the current token from the reader, - and this is written to the output file that was specified when it was - constructed. - - When there is no more input, the loop terminates, and the example can - exit successfully. -*/ diff --git a/examples/xml/xmlstreamlint/main.cpp b/examples/xml/xmlstreamlint/main.cpp deleted file mode 100644 index 5b445f87bd..0000000000 --- a/examples/xml/xmlstreamlint/main.cpp +++ /dev/null @@ -1,90 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -#include <QCoreApplication> -#include <QFile> -#include <QStringList> -#include <QTextStream> -#include <QXmlStreamReader> - -/* - This class exists for the sole purpose of creating a translation context. -*/ -class XmlStreamLint -{ -public: - Q_DECLARE_TR_FUNCTIONS(XmlStreamLint) -}; - -int main(int argc, char *argv[]) -{ - enum ExitCode - { - Success, - ParseFailure, - ArgumentError, - WriteError, - FileFailure - }; - - QCoreApplication app(argc, argv); - - QTextStream errorStream(stderr); - - if (argc != 2) - { - errorStream << XmlStreamLint::tr( - "Usage: xmlstreamlint <path to XML file>\n"); - return ArgumentError; - } - - QString inputFilePath(QCoreApplication::arguments().at(1)); - QFile inputFile(inputFilePath); - - if (!QFile::exists(inputFilePath)) - { - errorStream << XmlStreamLint::tr( - "File %1 does not exist.\n").arg(inputFilePath); - return FileFailure; - - } else if (!inputFile.open(QIODevice::ReadOnly)) { - errorStream << XmlStreamLint::tr( - "Failed to open file %1.\n").arg(inputFilePath); - return FileFailure; - } - - QFile outputFile; - if (!outputFile.open(stdout, QIODevice::WriteOnly)) - { - errorStream << XmlStreamLint::tr("Failed to open stdout."); - return WriteError; - } - -//! [0] - QXmlStreamReader reader(&inputFile); - QXmlStreamWriter writer(&outputFile); -//! [0] - -//! [1] - while (!reader.atEnd()) - { - reader.readNext(); - - if (reader.error()) - { - errorStream << XmlStreamLint::tr( - "Error: %1 in file %2 at line %3, column %4.\n").arg( - reader.errorString(), inputFilePath, - QString::number(reader.lineNumber()), - QString::number(reader.columnNumber())); - return ParseFailure; -//! [1] - -//! [2] - } else - writer.writeCurrentToken(reader); - } -//! [2] - - return Success; -} diff --git a/examples/xml/xmlstreamlint/xmlstreamlint.pro b/examples/xml/xmlstreamlint/xmlstreamlint.pro deleted file mode 100644 index 90a6387afe..0000000000 --- a/examples/xml/xmlstreamlint/xmlstreamlint.pro +++ /dev/null @@ -1,7 +0,0 @@ -CONFIG += cmdline -QT -= gui -SOURCES += main.cpp - -# install -target.path = $$[QT_INSTALL_EXAMPLES]/xml/xmlstreamlint -INSTALLS += target |