QQmlError Class
QQmlError 类封装了 QML 错误。更多
头文件: | #include <QQmlError> |
CMake: | find_package(Qt6 REQUIRED COMPONENTS Qml) target_link_libraries(mytarget PRIVATE Qt6::Qml) |
qmake: | QT += qml |
公共函数
QQmlError() | |
QQmlError(const QQmlError &other) | |
int | column() const |
QString | description() const |
bool | isValid() const |
int | line() const |
QtMsgType | messageType() const |
QObject * | object() const |
void | setColumn(int column) |
void | setDescription(const QString &description) |
void | setLine(int line) |
void | setMessageType(QtMsgType messageType) |
void | setObject(QObject *object) |
void | setUrl(const QUrl &url) |
QString | toString() const |
QUrl | url() const |
QQmlError & | operator=(const QQmlError &other) |
相关非成员
QDebug | operator<<(QDebug debug, const QQmlError &error) |
详细描述
QQmlError 包含错误的文本描述以及位置信息(文件、行和列)。例如,toString() 方法会创建一个包含所有这些信息的单行、人类可读字符串:
file:///home/user/test.qml:7:8: Invalid property assignment: double expected
您可以使用qDebug()、qInfo() 或qWarning() 向控制台输出错误信息。该方法将尝试打开错误所指示的文件,并包含额外的上下文信息。
file:///home/user/test.qml:7:8: Invalid property assignment: double expected y: "hello" ^
另请参阅 QQuickView::errors() 和QQmlComponent::errors()。
成员函数文档
QQmlError::QQmlError()
创建一个空的错误对象。
QQmlError::QQmlError(const QQmlError &other)
创建other 的副本。
int QQmlError::column() const
返回错误列的编号。
另请参阅 setColumn()。
QString QQmlError::description() const
返回错误描述。
另请参见 setDescription()。
bool QQmlError::isValid() const
如果该错误有效,则返回 true,否则返回 false。
int QQmlError::line() const
返回错误行号。
另请参见 setLine().
QtMsgType QQmlError::messageType() const
返回信息类型。
另请参阅 setMessageType().
QObject *QQmlError::object() const
返回发生此错误的最近对象。绑定属性表达式中的异常会将其设置为该属性所属的对象。对于所有其他异常,该值将为 0。
另请参阅 setObject()。
void QQmlError::setColumn(int column)
设置错误column 编号。
另请参阅 column().
void QQmlError::setDescription(const QString &description)
设置错误description 。
另请参阅 description() 。
void QQmlError::setLine(int line)
设置错误line 编号。
另请参阅 line().
void QQmlError::setMessageType(QtMsgType messageType)
为该信息设置messageType 。消息类型决定了哪些QDebug 处理程序负责接收消息。
另请参阅 messageType() 。
void QQmlError::setObject(QObject *object)
设置发生错误的最近object 。
另请参见 object()。
void QQmlError::setUrl(const QUrl &url)
设置导致该错误的文件的url 。
另请参阅 url().
QString QQmlError::toString() const
以人类可读字符串的形式返回错误信息。
QUrl QQmlError::url() const
返回导致该错误的文件的 url。
另请参见 setUrl()。
QQmlError &QQmlError::operator=(const QQmlError &other)
为该错误对象指定other 。
© 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.