Important: Please read the Qt Code of Conduct -

[Solved] qmake: variables scope

  • Hi all,
    I have a strange problem with variables' scope.
    I needed a simple function to append a directory to sources/headers, so what I did is:
    _DIR_NAME = $$1
    _SOURCES = $$2
    _HEADERS = $$2
    for(a, $$_SOURCES):SOURCES += $${_DIR_NAME}$${a}
    for(a, $$_SOURCES):HEADERS += $${_DIR_NAME}$${a}
    If I echo the SOURCES inside the function's scope it's fine but outside everything is undefined as if I'm dealing with a local variable! Am I missing something?
    Thank you for your help!

  • Well, I found the solution:
    _DIR_NAME = $$1
    _SOURCES = $$2
    _HEADERS = $$2
    for(a, _SOURCES):SOURCES += $${_DIR_NAME}$${a}
    for(a, _SOURCES):HEADERS += $${_DIR_NAME}$${a}
    To bad that this neither documented in the Qt qmake documentation nor in the 'Undocumented qmake' web page...

Log in to reply