1

I work on a Qt project and I use cmake. In my CMakeLists.txt I have:

target_compile_definitions(${PROJECT_NAME} PUBLIC
        QT_DEBUG_NO_OUTPUT
        QT_NO_INFO_OUTPUT
        QT_NO_WARNING_OUTPUT
        )

and to test that in my main.cpp I have:

#ifndef NDEBUG
    qDebug() << "QDEBUG IS ACTIVE!";
    std::cout << "Compiled in DEBUG\n";
#else
    qDebug() << "QDEBUG IS ACTIVE!";
    std::cout << "Compiled in RELEASE\n";
#endif

Does not matter if I compile in Release or Debug configuration, the line "QDEBUG IS ACTIVE!" gets printed.

P.S. I get correct cout for release and debug, so the configurations are working!

What am I doing wrong?

DEKKER
  • 877
  • 6
  • 19
  • You can use the logging category filter rules and make it based on a setting or command line argument: `QLoggingCategory::setFilterRules(...);` You can turn on and off specific types of messages. – slayer Mar 25 '22 at 14:24
  • 1
    Or you can try [Link](https://stackoverflow.com/questions/8801584/does-qt-offer-a-guaranteed-debug-definition) – slayer Mar 25 '22 at 14:28
  • 1
    "Does not matter if I compile in Release or Debug configuration, the line "QDEBUG IS ACTIVE!" gets printed." - This is expectable, as you have the **same line** `qDebug() << "QDEBUG IS ACTIVE!";` in both `#ifndef` and `#else` branches. – Tsyvarev Mar 25 '22 at 16:27
  • @Tsyvarev No! it should not print, the point is I expect it not to print anything! – DEKKER Mar 27 '22 at 16:25
  • 1
    If you expect `qDebug` to print nothing, then you should define `QT_NO_DEBUG_OUTPUT` macro (not a `QT_DEBUG_NO_OUTPUT` as in your current code). – Tsyvarev Mar 27 '22 at 17:16
  • @Tsyvarev yeah I was using the wrong macro apparently and the one you said is the correct one – DEKKER Mar 29 '22 at 07:02

1 Answers1

1

Change the typo QT_DEBUG_NO_OUTPUT to QT_NO_DEBUG_OUTPUT in order to use qDebug.

If you want to disable qDebug, qInfo and qWarning for a Release build only, then add the following condition to CMakeLists.txt:

string(TOLOWER ${CMAKE_BUILD_TYPE} build_type)
if (build_type STREQUAL release)
    target_compile_definitions(${PROJECT_NAME} PUBLIC
        QT_NO_DEBUG_OUTPUT
        QT_NO_INFO_OUTPUT
        QT_NO_WARNING_OUTPUT
        )
endif()
qqNade
  • 1,942
  • 8
  • 10
  • Oh man! I the defines I was using are wrong! maybe they belong to Qt4? I picked them from an old page in google. Thanks! – DEKKER Mar 29 '22 at 07:00