我在一個 Qt 專案上作業,我使用 cmake。在我的 CMakeLists.txt 我有:
target_compile_definitions(${PROJECT_NAME} PUBLIC
QT_DEBUG_NO_OUTPUT
QT_NO_INFO_OUTPUT
QT_NO_WARNING_OUTPUT
)
并在我的 main.cpp 中進行測驗,我有:
#ifndef NDEBUG
qDebug() << "QDEBUG IS ACTIVE!";
std::cout << "Compiled in DEBUG\n";
#else
qDebug() << "QDEBUG IS ACTIVE!";
std::cout << "Compiled in RELEASE\n";
#endif
如果我在 Release 或 Debug 配置中編譯,“QDEBUG IS ACTIVE!”行并不重要 被列印出來。
PS 我得到了正確的發布和除錯 cout,所以配置作業正常!
我究竟做錯了什么?
uj5u.com熱心網友回復:
將錯字 QT_DEBUG_NO_OUTPUT 更改為 QT_NO_DEBUG_OUTPUT 以使用 qDebug。
如果您只想對 Release 版本禁用 qDebug、qInfo 和 qWarning,則將以下條件添加到 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()
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/452361.html
上一篇:屬性更新不會更改組件中的值
