LoggingCategory QML Type

定义 QML 中的日志类别。更多

Import Statement: import QtQml

属性

详细说明

日志类别可作为第一个参数传递给 console.log() 和 friends。如果向日志程序提供了 LoggingCategory 名称,则日志类别将被用作日志类别。否则,将使用默认的日志类别。

import QtQuick

Item {
    LoggingCategory {
        id: category
        name: "com.qt.category"
        defaultLogLevel: LoggingCategory.Warning
    }

    Component.onCompleted: {
        console.log(category, "log message");
        console.warn(category, "warning message");
    }
}

默认情况下,它只输出com.qt.category: warning message 。由于defaultLogLevellog message 会被抑制。不过,您可以为 QML 日志类别配置日志级别,就像为QLoggingCategory 配置日志级别一样。

注意: 由于创建对象的成本很高,建议将所需的 LoggingCategory 定义放入单例中,并在需要时导入。

另请参阅 QLoggingCategory

属性文档

defaultLogLevel : enumeration

日志类别的默认日志级别。默认情况下,它是以LoggingCategory.Debug 日志级别创建的。

可使用以下枚举值:

它们反映了QtMsgType 枚举的值。

注意: 该属性需要在声明LoggingCategory 时设置,以后不能更改。

另请参阅 QtMsgType


name : string

日志类别名称。

注: 此属性需在声明LoggingCategory 时设置,以后不可更改。

另请参阅 QLoggingCategory::categoryName() 。


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