[Solved] .pro file questions (custom variables, mkspecs and contains())



  • My environment is Ubuntu 12.04 LTS, with Qt Creator 2.5.2, 64 bits.

    I'm dealing with .pro file in a project, trying to figure how it works. I've found some inconsistences I'd like to ask about.

    CUSTOM VARIABLES AND CONTAINS

    If I write in .pro file
    @MYVAR = "Mommy";
    message($$MYVAR)
    contains( MYVAR , Mommy )
    {
    message("got Mommy")
    }
    contains( MYVAR, Daddy )
    {
    message("got Daddy")
    }
    @

    compiling gives me this output:
    @Project MESSAGE: Mommy;
    Project MESSAGE: got Mommy
    Project MESSAGE: got Daddy@

    "contains( MYVAR, Daddy )" is not working as expected (same with $$MYVAR)!! "contains( MYVAR, Daddy )" block should not be executed, but it does... ¿why?

    MKSPECS USAGE

    According to Qt documentation, we can use mkspecs variables to check compiling platform.

    well, if I put
    @linux-g++-64
    {
    message("Linux 64 bits with g++")
    }
    @

    Building complains with this error:
    @Parse Error ('linux-g++-64')
    error: [Makefile] Error 3@

    Why? I've check /usr/share/qt4/mkspecs folder and there is a folder called "linux-g++-64"...



  • I believe you have a syntax error that may be the cause your issues:

    I am not on my code PC so I just took the first example I found on the internet to show you:
    @
    use_libs {
    LIBS += -lmylib1 -lmylib2
    } else {

    Stub out parts of the app by not including the libs.

    }
    @

    Note: the condition is followed immediatley by the braces "{" on the same line not on the line after (as you might do in c/c++). If I recall you must have the brace on the same line otherwise it is not part of the condition and all you end up with is seperate lines of code which all execute (as you have in your mommy/daddy example.

    I am fairly certain that will fix your first issue, it might fix the second if it is complaining about just calling "linux-g++-64" on its own.

    So you may end up with:
    @
    MYVAR = "Mommy";
    message($$MYVAR)
    contains( MYVAR , Mommy ) {
    message("got Mommy")
    }
    contains( MYVAR, Daddy ) {
    message("got Daddy")
    }
    @

    and

    @
    linux-g++-64 {
    message("Linux 64 bits with g++")
    }
    @



  • Yeah, man, you pointed in the right direction!! Now it works as expected.

    Final right codes are:

    @MYVAR = "Mommy"
    message($$MYVAR)
    contains( MYVAR , Mommy ){
    message("got Mommy")
    }
    contains( MYVAR, Daddy ){
    message("got Daddy")
    }@

    Notice A: MYVAR = "Mommy" with no ";" at end
    Notice B: "{" in same line as "contains( variable, value ) {"

    and

    @linux-g++-64 {
    message("Linux 64 bits with g++")
    }

    tru64-g++ {
    message("Hala")
    }

    linux-g++ {
    message("generic linux g++")
    }@

    Notice C: "{" in same line (again) as mkspec value
    Notice D: I expected "linux-g++-64" would be my mkspec, but looking carefully in Compile Output, I saw this: "-spec /usr/share/qt4/mkspecs/linux-g++" as qmake's argument. So, in this case my mkspec is "linux-g++".

    Thanks, Code_Fodder. Telepathycal beer for you!!



  • bq. Thanks, Code_Fodder. Telepathycal beer for you!!

    lol.....thanks!


Log in to reply
 

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