[Qt-interest] initialize variable to an environment variable or to a default

Lorenzo Bettini bettini at dsi.unifi.it
Sun Aug 30 16:21:08 CEST 2009


Hi

I'm still not very familiar with qmake; I'd like to initialize a 
variable in a project file to the value of an environment variable (with 
the same name) if set, or to a default value; for instance I do

QTDIR = $$(QTDIR)
isEmpty( QTDIR ) {
QTDIR = "/usr/bin"
}

now, I need to do this for many variables and I wanted to make a 
function for it... in a function I can do this

defineReplace(fromEnv) {
     variablename = $$1
     defaultValue = $$2
     message("variable " $$variablename)
     message("default value " $$defaultValue)
     isEmpty($$variablename) {
         message("empty variable")
     } else {
         message("not empty variable")
         message("value is " $$eval($$variablename))
     }
}

and call it like this

$$fromEnv("QTDIR", "/usr/bin")

however with $$eval($$variablename) I get the value of QTDIR, while I'd 
need to check $$(QTDIR), but $$(variablename) does not seem to work...
so, in a function you can get the value of a variable given its name, 
but not the value of an environment variable given its name, am I right?

thanks in advance
	Lorenzo

-- 
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
ICQ# lbetto, 16080134     (GNU/Linux User # 158233)
HOME: http://www.lorenzobettini.it MUSIC: http://www.purplesucker.com
http://www.myspace.com/supertrouperabba
BLOGS: http://tronprog.blogspot.com  http://longlivemusic.blogspot.com
http://www.gnu.org/software/src-highlite
http://www.gnu.org/software/gengetopt
http://www.gnu.org/software/gengen http://doublecpp.sourceforge.net




More information about the Qt-interest-old mailing list