Best practice for setting Windows .exe properties with Qt Creator?



  • Is putting

    VERSION = 0.0.0.1
    QMAKE_TARGET_COMPANY = company
    QMAKE_TARGET_PRODUCT = product
    QMAKE_TARGET_DESCRIPTION = description
    QMAKE_TARGET_COPYRIGHT = copyright

    in the .pro file the best way to do it?

    Also, I was trying to make the appname and version to show on my app title, but somehow I get an error.

    I add these lines to the .pro file:

    DEFINES += APP_NAME=\"Test Name Application\"
    VERSION = 1.2.3
    DEFINES += APP_VERSION=\"$$VERSION\"

    and this line to the main.cpp file:

    w.setWindowTitle(QString(APP_NAME).replace("_"," ") + QString(" - ") + APP_VERSION);

    But I get the following errors when compiling:

    C2065: 'Test': identifier not declared
    C2228: left of '.replace' must have class/struct/union


  • Lifetime Qt Champion

    Hi,

    You're not escaping your quotes enough for your defines on Windows.

    An alternative would be to use QMAKE_SUBSTITUTES and generate a header which will contain the info you want.

    Hope it helps.



  • Actually, I can't understand. Couldn't you please provide the lines of codes you generally use for populating the properties fields for a Windows application?


  • Lifetime Qt Champion

    I was talking about your DEFINES.

    I usually used an rc file and haven't yet used QMAKE_TARGET_COMPANYand its friends.



  • Hi @racingame,

    Couldn't you please provide the lines of codes you generally use for populating the properties fields for a Windows application?

    Like @SGaist, I tend you use my own rc file (just allows you to do a whole lot more than qmake is aware of), but you can see plenty of real-world examples on GitHub via a code search like this one: https://github.com/search?l=QMake&q=QMAKE_TARGET_COMPANY&type=Code

    As for:

    DEFINES += APP_NAME=\"Test Name Application\"
    VERSION = 1.2.3
    DEFINES += APP_VERSION=\"$$VERSION\"
    

    The problem here is that the arguments are not being escaped correctly when passed to the compiler. For this, I suggest you use QMake's shell_quote function like:

    DEFINES += APP_NAME=$$shell_quote(\"Test Name Application\")
    VERSION = 1.2.3
    DEFINES += APP_VERSION=$$shell_quote(\"$$VERSION\")
    

    Cheers.


Log in to reply
 

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