美好的一天。
我需要在我的Qt代码中访问特定的QBS变量。
一个例子是应用程序的名称,组织或风味,所有在我的应用程序qbs文件中指定的变量。
>>> reordered = df.sample(n=df.shape[0])
>>> lim = reordered[reordered.Money.cumsum() < 80000000]
在查看QBS的Qt文档时,我找不到在Qt代码中使用QBS变量的任何参考。
This是使用QBS变量的唯一链接,但仅在QBS文件内
我想这样做:
import qbs
Project {
// These variables should be available in C++ code.
name: "my_app_name"
organization: "Organisation_Name"
flavour:"AppFlavour"
minimumQbsVersion: "1.7.1"
CppApplication {
files: [
]
Depends { name: "Qt"; submodules: ['core', 'network'] }
cpp.cxxLanguageVersion: "c++11"
cpp.defines: [
"QT_DEPRECATED_WARNINGS",
]
consoleApplication: true
Group {
name: "source"
files: [
"qconfigurationmanager.cpp",
]
}
Group {
name: "header"
files: [
"qconfigurationmanager.h",
]
}
Group { // Properties for the produced executable
fileTagsFilter: "application"
qbs.install: true
}
}
}
我该怎么做?
答案 0 :(得分:3)
一个可能的选择是使用DEFINES并通过宏获取数据:
import qbs
Project {
minimumQbsVersion: "1.7.1"
property string name: "my_app_name"
property string organization: "Organisation_Name"
property string flavour:"AppFlavour"
CppApplication {
Depends { name: "Qt"; submodules: ['core', 'network']}
cpp.cxxLanguageVersion: "c++11"
consoleApplication: true
cpp.defines: [
"QT_DEPRECATED_WARNINGS",
"name=" + project.name,
"organization=" + project.organization,
"flavour=" + project.flavour
]
...
#define QUOTE_(x) #x
#define QUOTE(x) QUOTE_(x)
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QString appname = QUOTE(name);
QString organization = QUOTE(organization);
QString appflavour = QUOTE(flavour);
qDebug()<< appname << organization << appflavour;
...
输出:
"my_app_name" "Organisation_Name" "AppFlavour"