1、解决方案1
Since Qt5 you can use QT_ARCH to detect whether your configuration is 32 or 64. When the target is 32-bit, that returns i386 and in case of a 64-bit target it has the value of x86_64. So it can be used like:
1 contains(QT_ARCH, i386) {
2 message("32-bit")
3 } else {
4 message("64-bit")
5 }
2、解决方案2
貌似也有人用QMAKE_TARGET.arch进行判断,但是可能只适用windows,不适合跨平台。
1 win32 {
2 ## Windows common build here
3 !contains(QMAKE_HOST.arch, x86_64) {
4 message("x86 build")
5 ## Windows x86 (32bit) specific build here
6 } else {
7 message("x86_64 build")
8 ## Windows x64 (64bit) specific build here
9 }
10 }
3、解决方案3
利用自定义的字符变量进行判断。
Qt allows you to pass arbitrary config parameters which you can use to separate the targets.
By having a conditional config in your project file:
1 CONFIG(myX64, myX64|myX32) {
2 LIBPATH += C:\Coding\MSSDK60A\Lib\x64
3 } else {
4 LIBPATH += C:\Coding\MSSDK60A\Lib
5 }
and passing that custom config to qmake with
qmake CONFIG+=myX64
you get the wanted result.
4、解决方案4
The following code works on Windows (at least with all the recent MSVC compilers - didn't test MinGW), Mac OS X (clang) and Linux (GCC). Feel free to omit the first clause and refer to QT_ARCH directly if you don't need Qt 4 support.
1 #Firstly,Set TARGET_ARCH variable.
2 greaterThan(QT_MAJOR_VERSION, 4) {
3 TARGET_ARCH=$${QT_ARCH}
4 } else {
5 TARGET_ARCH=$${QMAKE_HOST.arch}
6 }
7 #Secondly, use TARGET_ARCH to check.
8 contains(TARGET_ARCH, x86_64) {
9 ARCHITECTURE = x64
10 } else {
11 ARCHITECTURE = x86
12 }
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全网最简单!3分钟用满血DeepSeek R1开发一款AI智能客服,零代码轻松接入微信、公众号、小程
· .NET 10 首个预览版发布,跨平台开发与性能全面提升
· 《HelloGitHub》第 107 期
· 全程使用 AI 从 0 到 1 写了个小工具
· 从文本到图像:SSE 如何助力 AI 内容实时呈现?(Typescript篇)
2021-09-26 OpenCV 找出图像中最小值最大值函数minMaxLoc的使用
2021-09-26 OpenCV 截取图像中某一区域的方法