Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. Using a string defined in project(.pro)
QtWS25 Last Chance

Using a string defined in project(.pro)

Scheduled Pinned Locked Moved Solved Qt Creator and other tools
qmakeqmake variablesdefinesstring
5 Posts 3 Posters 13.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    evanol
    wrote on last edited by A Former User
    #1

    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?

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by A Former User
      #2

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

      E 1 Reply Last reply
      1
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

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

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        1
        • ? Offline
          ? Offline
          A Former User
          wrote on last edited by A Former User
          #4

          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;
          
          1 Reply Last reply
          1
          • ? A Former User

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

            E Offline
            E Offline
            evanol
            wrote on last edited by evanol
            #5

            @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.

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved