Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable QML console.log() messages

Tags:

javascript

qt

qml

We are tunning the final release of our application, and we successfully disable the debug messages in 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.

I also found this source that clearly states: The output is generated using the qDebug, qWarning, qCritical methods in C++ (see also Debugging Techniques).

What doesnt make much sense to me, since Im already ignoring all the qDebugs()

So, the question is: How to ignore all the console.log() ?

I just think it should be an easy task, similar to the qDebug() messages.

For any further information, please leave a comment.

Note: I know that the link is for Qt 5., but im using Qt 4.8.

Thanks in advance!

like image 713
David Sánchez Avatar asked Feb 01 '26 12:02

David Sánchez


1 Answers

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(). 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.


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_LOGGING_RULES=qml=false
like image 130
Mitch Avatar answered Feb 04 '26 01:02

Mitch



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!