即使选择了Debug构建,Qt Creator的intellisense也会使#ifdef _DEBUG块变灰

sas*_*alm 6 c++ qt conditional-compilation qt-creator

当我在我的代码中有#ifdef这样的

#ifdef _DEBUG
    printf("This is a debug build");
#endif
Run Code Online (Sandbox Code Playgroud)

printf即使它是一个调试版本,Qt Creator仍会显示灰色,当我运行它时"This is a debug build"会打印出来.

似乎intellisense没有看到预处理器定义将通过命令行(即-D_DEBUG)传递给编译器,而不是在头文件/源文件中定义.

Mic*_*ild 11

以下在我的*.pro文件中工作得很好:

CONFIG(debug, release|debug):DEFINES += _DEBUG
Run Code Online (Sandbox Code Playgroud)

切换构建类型然后也交换灰色区域.不过,我正在使用Qt5.