Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. using Git version number in app

using Git version number in app

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 1.1k Views 2 Watching
  • 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.
  • mzimmersM Offline
    mzimmersM Offline
    mzimmers
    wrote on last edited by
    #1

    Hi all -

    I'm trying to automate the versioning of my application by using the value stored in a git tag. I found this article, which looks like a good start, but isn't working for me.

    Here's what I've tried (from the article): in my project file, I've added this:

    GIT_VERSION = $$system(git --git-dir="C:/wifibutton"/.git --work-tree="C:/wifibutton" describe --always --tags)
    DEFINES += APP_VERSION=\\"$$GIT_VERSION\\"
    

    If I'm reading the article correctly, APP_VERSION should be available to me in my c++ code. But when I try this:

        QString version(APP_VERSION);
    

    I get an "expected expression" error, which suggests to me that APP_VERSION isn't finding its way into my code space. Can someone tell me what I'm doing wrong?

    Thanks...

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

      Hi,

      Getting a string in a define on the command line can be pretty tricky because of the quote escaping you have to do.

      One simpler thing you can do is to generate a header from a template.

      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
      2
      • mzimmersM Offline
        mzimmersM Offline
        mzimmers
        wrote on last edited by
        #3

        Hi SGaist - can you please elaborate?

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

          You have a nice example here.

          Basically, you have a header template which contains the variables you want to substitute and in your build folder you'll get the header you want with the content you wanted.

          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
          3
          • mzimmersM Offline
            mzimmersM Offline
            mzimmers
            wrote on last edited by
            #5

            Very, very interesting. Never knew about that QMAKE_SUBSTITUTES.

            In my project file:

            GIT_VERSION = $$system(git --git-dir="C:/wifibutton"/.git --work-tree="C:/wifibutton" describe --always --tags)
            win32
            {
                // this is to remove characters that could prevent compilation.
                GIT_VERSION ~= s/-\d+-g[a-f0-9]{6,} 
            }
            QMAKE_SUBSTITUTES += config.h.in
            

            and config.h.in:

            #ifndef CONFIG_H_IN
            #define CONFIG_H_IN
            
            #define APP_VERSION '"$$GIT_VERSION"'
            
            #endif // CONFIG_H_IN
            

            and in my source code:

                QString version(APP_VERSION);
                // etc.
            

            Thanks!

            1 Reply Last reply
            1

            • Login

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