Why does qDebug work in Release builds?

sashoalm picture sashoalm · Nov 21, 2012 · Viewed 15k times · Source

Coming from MFC, I treated qDebug() much like TRACE(), assuming that it is removed from Release builds by the preprocessor (in MFC it's done using #define TRACE 1 ? (void*) 0 : AfxTrace).

To my surprise, however, qDebug() is executed in Release builds as well. How do I change this? And also, why is this so, what was the reasoning of the developers of Qt behind this decision?

Answer

qDebug is also preprocessor-controlled, but it has its own special macro, QT_NO_DEBUG_OUTPUT. If you add that to your Release build defines, it will be removed.