QXmlErrorHandler Class

QXmlErrorHandler 类提供了一个接口,用于报告 XML 数据中的错误。更多

Header: #include <QXmlErrorHandler>
CMake: find_package(Qt6 REQUIRED COMPONENTS Core5Compat)
target_link_libraries(mytarget PRIVATE Qt6::Core5Compat)
qmake: QT += core5compat
继承于

QXmlDefaultHandler

注意:该类中的所有函数都是可重入的

公共函数

virtual ~QXmlErrorHandler()
virtual bool error(const QXmlParseException &exception) = 0
virtual QString errorString() const = 0
virtual bool fatalError(const QXmlParseException &exception) = 0
virtual bool warning(const QXmlParseException &exception) = 0

详细说明

如果您希望应用程序向用户报告错误或执行自定义错误处理,则应子类该类。

您可以使用QXmlReader::setErrorHandler() 设置错误处理程序。

可以使用warning(),error() 和fatalError() 报告错误,并使用errorString() 报告错误文本。

另请参见 QXmlDTDHandler,QXmlDeclHandler,QXmlContentHandler,QXmlEntityResolverQXmlLexicalHandler

成员函数文档

[virtual noexcept] QXmlErrorHandler::~QXmlErrorHandler()

销毁错误处理程序。

[pure virtual] bool QXmlErrorHandler::error(const QXmlParseException &exception)

读者可以使用该函数来报告可恢复的错误。可恢复错误与 XML 1.0 规范第 1.2 节中的 "错误 "定义相对应。错误的详细信息存储在exception 中。

调用此函数后,阅读器必须继续提供正常的解析事件。

如果该函数返回false ,阅读器将停止解析并报告错误。阅读器使用函数errorString() 获取错误信息。

[pure virtual] QString QXmlErrorHandler::errorString() const

如果有处理函数返回false ,阅读器会调用该函数获取错误字符串。

[pure virtual] bool QXmlErrorHandler::fatalError(const QXmlParseException &exception)

读者必须使用该功能报告不可恢复的错误。错误的详细信息存储在exception 中。

如果该函数返回true ,阅读器可能会尝试继续解析并报告更多错误,但不会报告常规解析事件。

[pure virtual] bool QXmlErrorHandler::warning(const QXmlParseException &exception)

读者可以使用该函数报告警告。警告是指不属于 XML 1.0 规范定义的错误或致命错误的情况。警告的详细信息存储在exception 中。

如果该函数返回false ,阅读器就会停止解析并报告错误。阅读器使用函数errorString() 获取错误信息。

© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.