Qt DEFINES 在项目文件中不起作用
我有一个这样开始的项目文件:
VERSION = 0.9.9.0
DEFINES += VERSION_NUMBER=$${VERSION}
因此,我定义了一个新的常量 VERSION_NUMBER,然后我可以在源代码中访问它。但是,稍后当我这样做时:
qDebug() << VERSION_NUMBER;
编译器告诉我错误:C2143:语法错误:缺少“;”在“constant”之前,就好像未定义 VERSION_NUMBER。有谁知道可能是什么原因?
I have a project file that starts like this:
VERSION = 0.9.9.0
DEFINES += VERSION_NUMBER=${VERSION}
So I define a new constant VERSION_NUMBER that I can then access in the source code. However, later when I do:
qDebug() << VERSION_NUMBER;
The compilers tells me error: C2143: syntax error : missing ';' before 'constant'
as if VERSION_NUMBER was not defined. Does anybody know what could be the reason?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您在这里需要解决三个问题。首先,您需要将
VERSION_NUMBER=$${VERSION}
赋值放在引号内:向 qmake 添加一个带有值的定义?
第二个是让 QMake 传入字符串文字并不是太容易
#define
。很多方法只会将按句点分隔的数字解释为格式不良的数字常量:http://robertcarlsen.net/2009/01/06/qmake-xcode-bug-258
这可能会让你在某个地方问题...适用于我的设置,尽管这是一个三重问题:
第三个问题 - 可能是最大的 - 是你正在使用 QMake,它已经过时了,Trolltech/Nokia 的人都知道它:
http://labs.qt.nokia.com/2009/10/12/to-make-or-not-to-make-qmake-and-beyond/
您应该切换到其他内容(就像 CMake...它支持 Qt 并由 KDE 使用)。
You've got three issues to address here. First is that you need to put that
VERSION_NUMBER=$${VERSION}
assignment inside of quotes:Add a define to qmake WITH a value?
The second is that it's not overly easy to get QMake to pass in a string literal
#define
. A lot of ways will just interpret your numbers-separated-by-periods as a poorly formed numeric constant:http://robertcarlsen.net/2009/01/06/qmake-xcode-bug-258
This might get you somewhere with the issue...works on my setup, although it's a triple-escaped headache:
Third problem--probably the biggest--is that you're using QMake, which is outdated, and the Trolltech/Nokia people know it:
http://labs.qt.nokia.com/2009/10/12/to-make-or-not-to-make-qmake-and-beyond/
You should switch to something else (like CMake...which supports Qt and is used by KDE).