关于库相对路径以及如何重用 属性 字符串的 qbs 问题

qbs qestion about library relative path and how to reuse a property string

我正在尝试在由 qbs 1.5.1、Qt 5.6.1、Qt Creator 4.0.1 生成的项目中使用多个库

我目前有几个关于 qt building suit 的问题。

第一个问题:如何重用 属性 字符串?例如,我试图定义一个包含一些字符串属性的产品,并试图在项目的其他地方重用这些属性。

// defines the qbs file in subfolder settings/settings.qbs
import qbs

Product
{
  name: 'config'
  property string p1    : 'path1'         // <- define p1
  property string p2: p1 + '/path2'       // <- define p2
}

并尝试使用属性:

我。将 settings.qbs 添加到根 project.qbs

import qbs
import qbs.File

Project{
  references:{
  ...,
  "settings/settings.qbs"
  }
}

二。在另一个包含应用程序的文件夹中

// application/app.qbs
import qbs 

CppApplication{
  type: "application"
  name: "myapp"

  Depends {name: "cpp"}
  Depends {name: "config"}

  cpp.libraryPaths [config.p1, config.p2] // <- use p1 and p2 in a different qbs file
}

但是当我运行

qbs debug

在存储库根目录中,属性 字符串值为 'undefined'。

第二个问题是相对路径。似乎我可以在 files:[] 中使用相对路径,但是当我在 cpp.dynamicLibraries 或 cpp.staticLibraries 中使用相对路径时,编译器无法根据相对路径找到库。但是,如果我使用绝对路径,它就可以工作。我错过了什么吗?

感谢您的帮助:)

您不能引用那样的属性。您需要使用 QML 继承或导入 JavaScript 文件。比如你可以把JS代码放到单独的.js文件中,然后导入。

---helpers.js---
function planetsCorrectlyAligned()
{
    // implementation
}

---myproject.qbs---
import qbs 1.0
import "helpers.js" as Helpers

Product {
    name: "myproject"
    Group {
        condition: Helpers.planetsCorrectlyAligned()
        file: "magic_hack.cpp"
    }
    // ...
}

此语法在 Qbs 文档中有详细说明:https://doc.qt.io/qbs/language-introduction.html#reusing-project-file-code


我不是在别处回答了图书馆的问题吗?另外,请不要将多个问题添加到同一个 post; Stack Overflow 不是这样工作的。