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"
        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
            }
        }
    }
    

    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?



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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.