Important: Please read the Qt Code of Conduct -

QMake: Use string as variable

  • Hello,

    I have a string and I want to use it as part of another variable name

    QT_MODULE_NAME = xml
    # I would like to use something like this:
    LIB_PATH = $${QT.$${QT_MODULE_NAME}.libs}

    But it does not seem to work. I get Missing } terminator

    Any tips?

  • Moderators

    I don't think qmake supports nesting variable names like that. One thing you could try is to use different scoping methods:

    LIB_PATH = $${QT.$${QT_MODULE_NAME}.libs}
    # Or
    LIB_PATH = $${QT.$$(QT_MODULE_NAME).libs}
    # Or
    LIB_PATH = $${QT.${QT_MODULE_NAME}.libs}

    Dig through qmake documentation, maybe it will help.

    Alternative would be to build an array and iterate over it, like:

    QT_MODULE_NAMES = QT.xml QT.widgets QT.networking
    for (module, QT_MODULE_NAMES) {

    I have no idea if it will work with variable names - I doubt it.

  • Hi, try:

    LIB_PATH = $$eval(QT.$${QT_MODULE_NAME}.libs)

Log in to reply