【问题标题】:console.time doesn't support QLoggingCategory?console.time 不支持 QLoggingCategory?
【发布时间】:2018-03-09 07:47:50
【问题描述】:

我试图通过创建许多日志类别like documented here 来减少我的 QtQuick 应用程序中的日志输出量。

日志类别可以作为第一个参数传递给 console.log() 和朋友。如果提供给记录器,则 LoggingCategory 的名称将用作记录类别,否则将使用默认记录类别。

现在我正在尝试使用 console.time()console.timeEnd() (documented here) 来做到这一点。

我在日志输出中遇到一些错误:

qrc:/main.qml:16: Error: console.time(): Invalid arguments

如何使用 console.time() 的日志记录类别?

示例代码:

import QtQuick 2.9
import QtQuick.Window 2.2

Window {
    visible: true
    width: 640
    height: 480
    title: qsTr("Hello World")

    LoggingCategory {
        id: category
        name: "some.not.so.important.stuff"
    }

    Component.onCompleted: {
        console.time(category, 'start');
        console.timeEnd(category, 'start');
    }
}

【问题讨论】:

    标签: javascript qt qt5 qtquick2 console.log


    【解决方案1】:

    文档说的地方

    可以将日志记录类别传递给 console.log() 和朋友作为 第一个参数

    它指的是console.log、console.debug、console.info、console.warn和console.error,它们都是为了打印消息。

    其他控制台功能(Assert、Timer 等)不支持日志记录类别。

    【讨论】:

    • 这很可悲......我不明白“和朋友”这个词。有没有使用 if 的解决方法?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-05-04
    • 1970-01-01
    • 2018-10-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-27
    相关资源
    最近更新 更多