简体   繁体   English

禁用 QML console.log() 消息

[英]Disable QML console.log() messages

We are tunning the final release of our application, and we successfully disable the debug messages in c++.我们正在调整应用程序的最终版本,并成功禁用了 C++ 中的调试消息。

CONFIG(release, debug|release):{
    message(Building in release mode. We deactivate the logs.)
    DEFINES += QT_NO_DEBUG_OUTPUT
} else {
    message(Building in debug mode.)
}

But, our QML javascript console.log() functions are still logging the information.但是,我们的 QML javascript console.log() 函数仍在记录信息。

I also found this source that clearly states: The output is generated using the qDebug, qWarning, qCritical methods in C++ (see also Debugging Techniques).我还发现这个来源明确指出:输出是使用 C++ 中的 qDebug、qWarning、qCritical 方法生成的(另请参阅调试技术)。

What doesnt make much sense to me, since Im already ignoring all the qDebugs()什么对我来说没有多大意义,因为我已经忽略了所有 qDebugs()

So, the question is: How to ignore all the console.log() ?所以,问题是:如何忽略所有的 console.log() ?

I just think it should be an easy task, similar to the qDebug() messages.我只是认为这应该是一项简单的任务,类似于 qDebug() 消息。

For any further information, please leave a comment.如需更多信息,请发表评论。

Note: I know that the link is for Qt 5., but im using Qt 4.8.注意:我知道该链接适用于 Qt 5.,但我使用的是 Qt 4.8。

Thanks in advance!提前致谢!

If QT_NO_DEBUG_OUTPUT successfully disables output from within Qt code, it should do the same for the C++ functions that implement console.log() .如果QT_NO_DEBUG_OUTPUT成功禁用了 Qt 代码中的输出,它应该对实现console.log()C++ 函数执行相同的操作。 However, I believe that those feature macros are deliberately not auto-tested (too many macros, too few hardware resources to test them on), so any bug report would be closed, and you'd be encouraged to submit a patch yourself.但是,我相信这些功能宏是故意不自动测试的(宏太多,硬件资源太少,无法对其进行测试),因此将关闭任何错误报告,并鼓励您自己提交补丁。

Another solution might be to use qInstallMessageHandler() , as mentioned in the answers to this question.另一种解决方案可能是使用qInstallMessageHandler() ,如问题的答案中所述。


Unfortunately this doesn't help you, but in Qt 5, it's enough to disable the logging rule with the QT_LOGGING_RULES environment variable:不幸的是,这对您没有帮助,但在 Qt 5 中,使用QT_LOGGING_RULES环境变量禁用日志记录规则就足够了:

QT_LOGGING_RULES=qml=false

这是我用于最终版本的内容:

qputenv("QT_LOGGING_RULES", QByteArray("*.debug=false;qml=false"));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM