How to detect Qt Creator's target (debug/release) (Visual Studio)

落爺英雄遲暮 提交于 2019-12-01 17:36:07

The answer is I think in Qt project org faq 355

If you always accept the name Qt Creator suggests for your build you can use the following simple solution in your pro files that in my case (Qt 5.5) works for Linux, Mac and Windows:

# to distinguish between debug and release executable as target
# we define the variables releaseExec and debugExec
# this only works if the $$OUT_PWD has "Release" in its name
BDIR = $$OUT_PWD
BDIR_STRIPPED = $$replace(BDIR,Release,)
equals (BDIR,$$BDIR_STRIPPED): CONFIG+= debugExec
else: CONFIG+= releaseExec

We used the variables releaseExec and debugExec to avoid name collisions with Qt CONFIG variables.

You can now use the switch statements:

releaseExec: warning ("this is a release build")
debugExec: warning ("this is a debug build")
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!