Using a string defined in project(.pro)



  • Is there a way to define build/version information in the project file and then use it in your application.

    My application uses a version string as "1.23.4567" which i'm defining in my project file and using it to generate an opkg/ipk package (passing it to the CONTROL file).
    I want to be able to use the same definition within my C code so that i can use it with qApp->setApplicationVersion()

    currently i have the following information in my project(.pro) file

    #added versioning information to project
    APPLICATION_VERSION="1.23.4567"
    DEFINES += APPLICATION_VERSION
    VERSION  = $$APPLICATION_VERSION
    

    But when I try to use the define i get the following

    qDebug() << "APPLICATION_VERSION :" << QString( APPLICATION_VERSION );
    APPLICATION_VERSION : "\u0001"
    

    or

    qDebug() << "APPLICATION_VERSION :" <<  APPLICATION_VERSION;
    APPLICATION_VERSION : 1
    

    I've also tried

    #added versioning information to project
    APP_BUILD=4567
    APP_MINOR=23
    APP_MAJOR=1
    DEFINES += APP_MAJOR APP_MINOR APP_BUILD
    VERSION  = $$APP_MAJOR"."$$APP_MINOR"."$$APP_BUILD
    

    which results in the following:

    qDebug() << "APPLICATION_VERSION :" << APP_MAJOR << "," << APP_MINOR << "," << APP_BUILD;
    APPLICATION_VERSION : 1 , 1 , 1
    

    &

    qDebug() << "APPLICATION_VERSION :" << QString("%1.%2.%3").arg( APP_MAJOR, 1, 10, QChar('0') )
                                                                  .arg( APP_MINOR, 2, 10, QChar('0') )
                                                                  .arg( APP_BUILD, 4, 10, QChar('0') );
    APPLICATION_VERSION : "1.01.0001"
    

    Is there a way to expose the version information that I've defined in my project file to use within my code?



  • Hi! The following thread has the solution: Use qmake variable in cpp file.


  • Lifetime Qt Champion

    Hi,

    Why not use QCoreApplication::applicationVersion in conjunction with qmake VERSION variable ?



  • BTW, with Qbs it's as simple as:

    .qbs - file:

    cpp.defines: ["Something", "doStuff=1", 'WSS="something with whitespace"']
    

    in C++

    #ifdef Something
    qDebug() << "Something";
    #endif
    
    qDebug() << QString("doStuff: %1").arg(doStuff);
    qDebug() << WSS;
    


  • @Wieland Thanks for the reference - that has worked for me.

    Also, thanks for the Qbs information - i hadn't seen this before but will look into it

    @SGaist - thanks for the info

    I had previously tried something similar but I think it may have been the escaping of quotes which caught me out.



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