3

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!

David Sánchez
  • 544
  • 8
  • 21
  • You can try to use this http://stackoverflow.com/questions/1215392/how-to-quickly-and-conveniently-disable-all-console-log-statements-in-my-code for disabling console.log() – demonplus Nov 19 '15 at 10:52
  • I saw that post, but I think is using to much resources for something that should be easily implemented. AFAIK, with the QT_NO_DEBUG_OUTPUT Im pretty sure it literally removes the code, since the size of my app is reduced. I was expecting any similar macro. Thanks any way! :) – David Sánchez Nov 19 '15 at 22:19

2 Answers2

1

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
Community
  • 1
  • 1
Mitch
  • 23,716
  • 9
  • 83
  • 122
  • Hi! That was one of my possible solutions. I have successfully testested and I know it can work, but as I said before, i think is using to many resources (at the end, is a function calling other function). I was expecting a macro that will disable/remove the comments as QT_NO_DEBUG_OUTPUT. I will wait to see if other answers provide more info, if not I will accept this as the answer. +1 for the deep explanation of how is handle in qt project. – David Sánchez Nov 19 '15 at 22:22
0

Here is what I use for a final release:

qputenv("QT_LOGGING_RULES", QByteArray("*.debug=false;qml=false"));
Slava Rozhnev
  • 9,510
  • 6
  • 23
  • 39