这个问题主要是cmake那边的qt设置没弄好。其中WIN32_EXECUTABLE ON。这个选项要设置为OFF。不然qdebug无法打印到终端中。
如果本来就没有这set_target_properties的话,可以在cmake最后一行加上这个,并且将WIN32_EXECUTABLE ON设置为OFF即可。
set_target_properties( application PROPERTIES
WIN32_EXECUTABLE ON
MACOSX_BUNDLE ON
)
该问题在Qt社区其实已经有答案了:https://forum.qt.io/topic/142682/no-console-output-to-terminal-on-windows-when-using-cmake
也有第二种方法:
vscode生成的cmake文件一般会有这一段代码
add_executable(${PROJECT_NAME} # WIN32 # If you need a terminal for debug, please comment this statement (这段是已经在打印调试要注释了) ${srcs} )
浙公网安备 33010602011771号