一杯清酒邀明月
天下本无事,庸人扰之而烦耳。
posts - 3121,comments - 209,views - 578万

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 }
复制代码

 

posted on   一杯清酒邀明月  阅读(1477)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全网最简单!3分钟用满血DeepSeek R1开发一款AI智能客服,零代码轻松接入微信、公众号、小程
· .NET 10 首个预览版发布,跨平台开发与性能全面提升
· 《HelloGitHub》第 107 期
· 全程使用 AI 从 0 到 1 写了个小工具
· 从文本到图像:SSE 如何助力 AI 内容实时呈现?(Typescript篇)
历史上的今天:
2021-09-26 OpenCV 找出图像中最小值最大值函数minMaxLoc的使用
2021-09-26 OpenCV 截取图像中某一区域的方法
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示