本页内容

QXmlErrorHandler Class

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

标题: #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 、QXmlEntityResolver 以及QXmlLexicalHandler 。

成员函数文档

[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()来获取错误消息。

© 2026 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.