Getting values from pro files in Qt

前端 未结 2 1028
终归单人心
终归单人心 2021-02-05 08:32

I am using Qt 4.5 in Windows XP. My pro file has the variable VERSION = 1.0. Now i need to read this variable and get its value (1.0) from the source c

相关标签:
2条回答
  • 2021-02-05 08:56

    Use somethings like this:

    DEFINES += VERSION=\\\"$$VERSION\\\"
    

    This will define a macro that you can use in C source code. Get rid of the backslashes and quotes if you want a number, not a string.

    0 讨论(0)
  • 2021-02-05 08:59

    I'll elaborate on this a bit.

    In the YourApp.pro:

    VERSION = 0.0.0.1
    DEFINES += APP_VERSION=\\\"$$VERSION\\\"
    

    In the main.cpp:

    #include <QApplication>
    QCoreApplication::setApplicationVersion(QString(APP_VERSION));
    

    Wherever else in your sources, e.g. in the imaginary controller.cpp:

    #include <QApplication>
    QString yourAppVersion = QCoreApplication::applicationVersion();
    
    0 讨论(0)
提交回复
热议问题