在QMake中自定义方法

defineTest

defineTest定义的方法返回truefalse,多用于检查某一条件是否成立。使用方法名(参数, ...)来调用。

# 定义全局变量
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 = 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值