c++qtcmakeqt-creatorqdebug

Can not surpress QDebug output in relesae build


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?


Solution

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