我是qmake
新手,我正在试验项目结构。 我现在像这样构建我的项目
./src/
logic/
ui/
controller/
etc...
./inc/
logic/
ui/
controller/
etc...
我想创建一个函数,相应地正确包含一个新的 *.h 和 *.cpp 文件,所以我做了:
cont = "controller"
logic = "logic"
ui = "ui"
defineReplace(myFunction) {
path = $$1
name = $$2
HEADERS *= ./inc/$${path}/$${name}.h
SOURCES *= ./src/$${path}/$${name}.cpp
}
myFunction(cont,file1)
我预计结果就像我只是说:
HEADERS *= ./inc/controller/file1.h
SOURCES *= ./src/controller/file1.cpp
但我只是收到一个myFunction is not a recognized test function
.
我做错了什么?
我做错了什么?
Qmake在"replace"函数(即返回一个字符串,如make中的变量替换;通常用于赋值的rhs(和"test"函数(返回适合条件运算符的布尔值(之间进行区分。
myFunction(cont, file)
是测试函数的调用;$$myFunction(cont, file)
是对替换函数的调用。
另请注意,Qmake文件基本上由分配和条件组成。因此,myFunction(cont, file)
被解释为
myFunction(cont, file) {
# nothing
} else {
# nothing
}
另一个问题是 Qmake 中的函数使用自己的私有变量副本,因此您必须使用export()
来使您的更改在外部可见。因此,我们有:
# replace function example code
defineReplace(myFunction) {
HEADERS *= ./inc/$$1/$${2}.h
SOURCES *= ./src/$$1/$${2}.cpp
export(HEADERS)
export(SOURCES)
# warning: conditional must expand to exactly one word
#return()
# warning: conditional must expand to exactly one word
#return(foo bar)
# ok: any word will do as we don't care for true/false evaluation
return(baz)
}
# test function example code
defineTest(myFunction) {
HEADERS *= ./inc/$$1/$${2}.h
SOURCES *= ./src/$$1/$${2}.cpp
export(HEADERS)
export(SOURCES)
# warning: unexpected return value
#return(foo)
# ok: returns true
#return(true)
# ok: also returns true
#return()
# ...or simply return true by default
}
# calling replace function
$$myFunction(cont, file)
# calling test function
myFunction(cont, file)