defineTest
defineTest
定义的方法返回true
或false
,多用于检查某一条件是否成立。使用方法名(参数, ...)
来调用。
# 定义全局变量
GLOABL_VARIABLE = "Global Variable"
# 定义Test方法
defineTest(funTest) {
# 读取参数
message("1 = $$1")
message("2 = $$2")
# 读取全局变量
message("GLOABL_VARIABLE = $$GLOABL_VARIABLE")
# 设置局部变量
local_variable = "local variable"
message("local_variable = $$local_variable")
# 返回结果
isEmpty("$$1") {
return (true)
} else {
return (false)
}
}
# 调用自定义的Test方法
funTest("123", 456) {
message("return = True")
} else {
message("return = False")
}
# 无法再读取到局部变量的值
message("local_variable = $$local_variable")
Project MESSAGE: 1 = 123
Project MESSAGE: 2 = 456
Project MESSAGE: GLOABL_VARIABLE = Global Variable
Project MESSAGE: local_variable = local variable
Project MESSAGE: return = True
Project MESSAGE: local_variable =
defineReplace
defineReplace
定义的方法多用于修改字符串或列表。使用$$方法名(参数, ...)
来调用。
# 定义全局变量
GLOABL_VARIABLE = "Global Variable"
# 定义Replace方法
defineReplace(funReplace) {
# 读取参数
message("1 = $$1")
# 读取全局变量
message("GLOABL_VARIABLE = $$GLOABL_VARIABLE")
# 设置局部变量
local_variable = $$upper("$$1")
message("local_variable = $$local_variable")
# 返回结果
return ("$$local_variable")
}
# 调用自定义的Replace方法
result_value = $$funReplace("hello_qmake")
# 打印调用结果
message("result_value = $$result_value")
# 无法再读取到局部变量的值
message("local_variable = $$local_variable")
Project MESSAGE: 1 = hello_qmake
Project MESSAGE: GLOABL_VARIABLE = Global Variable
Project MESSAGE: local_variable = HELLO_QMAKE
Project MESSAGE: result_value = HELLO_QMAKE
Project MESSAGE: local_variable =