Disable qDebug output locally with a macro

I used qDebug throughout the code. Now I would like to limit its output to translation units, defining a separate macro to enable / disable qDebug output in the translation block:

test.pro:

DEFINES += NO_DEBUG_ONE

testone.cpp:

#ifdef NO_DEBUG_ONE
#define QT_NO_DEBUG_OUTPUT
#endif

testtwo.cpp:

#ifdef NO_DEBUG_TWO
#define QT_NO_DEBUG_OUTPUT
#endif

So by asking macros like this, I expected to get qDebug output only in testtwo.cpp, but I see qDebug messages from both translation units.

What am I missing here and how to solve it?

+4
source share
3 answers

Move your code to the beginning testone.cppand testtwo.cpp, and you should be good to go.

QT_NO_DEBUG_OUTPUT QT_NO_WARNING_OUTPUT , Qt.

cmake, , qmake.

+3

QMake, , . - -D TEST - .

#ifndef TEST
    qDebug() << "test";
#endif
0

, QT_NO_DEBUG_OUTPUT , Qt, ( ).

- , :

Unfortunately, all of these changes will require code changes.

0
source

Source: https://habr.com/ru/post/1612025/


All Articles