gpt4 book ai didi

qt - QMake中的变量比较

转载 作者:行者123 更新时间:2023-12-04 14:01:04 27 4
gpt4 key购买 nike

我知道在 QMake 中你可以使用 $$添加自定义变量参数的语法如下:

# In .pro
message($$FOO)
# In shell
$ qmake 'FOO="ABC"'

我也知道您也可以使用条件来检查当前平台之类的内容:
win32 {
# ...
}

使用这些语法的组合,您将如何定义条件来检查变量参数是否等于值?
# I want something like this:
$$FOO == "..." {
# ...
}

最佳答案

这是我们在 QtSerialPort 本身中使用的:

equals(variablename, value)

Tests whether variablename equals the string value.

For example:

TARGET = helloworld equals(TARGET, "helloworld") { message("The target assignment was successful.") }



您还可以使用这种“不等于”检查通常的方式,如下所示:
!equals(a, b) { ... }

您需要注意,因为包括这个在内的几个 qmake 函数需要有一个局部变量才能使用。将您的值传递给 qmake 并打印出变量是不够的。这是关于 qmake 的一个有点愚蠢的限制。

严格来说,您也可以使用以下函数进行比较,但这不是首选:

eval(string)

Evaluates the contents of the string using qmake syntax rules and returns true. Definitions and assignments can be used in the string to modify the values of existing variables or create new definitions.

For example:


eval(TARGET = myapp) {
message($$TARGET)
}

关于qt - QMake中的变量比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21007860/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com