Important: Please read the Qt Code of Conduct -

Access QBS variables in Qt code

  • Good day.

    I need to access specific QBS variables inside my Qt code.

    An example is the Application's name, organisation or even the flavour, all variables specified like this in my application qbs file.

    import qbs
    Project {
        // These variables should be available in C++ code.
        name: "my_app_name"
        organization: "Organisation_Name"
        minimumQbsVersion: "1.7.1"
        CppApplication {
            files: [
            Depends { name: "Qt"; submodules: ['core', 'network'] }
            cpp.cxxLanguageVersion: "c++11"
            cpp.defines: [
            consoleApplication: true
            Group {
                name: "source"
                files: [
            Group {
                name: "header"
                files: [
            Group {     // Properties for the produced executable
                fileTagsFilter: "application"
                qbs.install: true

    Looking at the Qt documentation for QBS, I did not find any reference to using QBS variables in Qt code.

    This is the only link of using QBS variables, but only within the QBS file

    I would like to do this:

    QString appflavour = Qbs.get("flavour")

    How can I do this?

  • Qt Champions 2020

    Define your variables via cpp.defines and use from C++.

Log in to reply