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. GIT_VERSION variable in .pro
Forum Updated to NodeBB v4.3 + New Features

GIT_VERSION variable in .pro

Scheduled Pinned Locked Moved Solved General and Desktop
16 Posts 4 Posters 1.9k Views 1 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.
  • I Offline
    I Offline
    ivanicy
    wrote on 2 Dec 2019, 10:10 last edited by
    #1

    Hello!!

    I am trying to use the git version in my app. I found this page in which it is explained how to do it.

    https://www.everythingfrontend.com/posts/app-version-from-git-tag-in-qt-qml.html

    but, when I try to follow the steps, I have an error "Expected expression":

    GIT_VERSION = $$system(git --git-dir $$PWD/.git --work-tree $$PWD describe --always --tags)
    DEFINES += GIT_VERSION=\\"$$GIT_VERSION\\"
    
    ...
    
    ui->labelVersion->setText(QString("App (version %1)").arg(QString(GIT_VERSION))); // <-- Expected expression
    

    What I am doing wrong?

    Thank you very much!

    K 1 Reply Last reply 2 Dec 2019, 11:02
    0
    • I ivanicy
      2 Dec 2019, 10:10

      Hello!!

      I am trying to use the git version in my app. I found this page in which it is explained how to do it.

      https://www.everythingfrontend.com/posts/app-version-from-git-tag-in-qt-qml.html

      but, when I try to follow the steps, I have an error "Expected expression":

      GIT_VERSION = $$system(git --git-dir $$PWD/.git --work-tree $$PWD describe --always --tags)
      DEFINES += GIT_VERSION=\\"$$GIT_VERSION\\"
      
      ...
      
      ui->labelVersion->setText(QString("App (version %1)").arg(QString(GIT_VERSION))); // <-- Expected expression
      

      What I am doing wrong?

      Thank you very much!

      K Offline
      K Offline
      KroMignon
      wrote on 2 Dec 2019, 11:02 last edited by
      #2

      @ivanicy said in GIT_VERSION variable in .pro:

      DEFINES += GIT_VERSION=\"$$GIT_VERSION\"

      change to: DEFINES += GIT_VERSION=\\\"$$GIT_VERSION\\\"
      And then it should work

      It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

      I 2 Replies Last reply 2 Dec 2019, 13:08
      4
      • K KroMignon
        2 Dec 2019, 11:02

        @ivanicy said in GIT_VERSION variable in .pro:

        DEFINES += GIT_VERSION=\"$$GIT_VERSION\"

        change to: DEFINES += GIT_VERSION=\\\"$$GIT_VERSION\\\"
        And then it should work

        I Offline
        I Offline
        ivanicy
        wrote on 2 Dec 2019, 13:08 last edited by
        #3

        @KroMignon Thank you very much!!

        K 1 Reply Last reply 2 Dec 2019, 13:33
        0
        • I ivanicy
          2 Dec 2019, 13:08

          @KroMignon Thank you very much!!

          K Offline
          K Offline
          KroMignon
          wrote on 2 Dec 2019, 13:33 last edited by
          #4

          @ivanicy your welcome ;) Don't forget to mark as solved!

          It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

          1 Reply Last reply
          0
          • K KroMignon
            2 Dec 2019, 11:02

            @ivanicy said in GIT_VERSION variable in .pro:

            DEFINES += GIT_VERSION=\"$$GIT_VERSION\"

            change to: DEFINES += GIT_VERSION=\\\"$$GIT_VERSION\\\"
            And then it should work

            I Offline
            I Offline
            ivanicy
            wrote on 2 Dec 2019, 15:50 last edited by
            #5

            @KroMignon And do you know how can I add the git date to this string?

            K 1 Reply Last reply 2 Dec 2019, 16:02
            0
            • I ivanicy
              2 Dec 2019, 15:50

              @KroMignon And do you know how can I add the git date to this string?

              K Offline
              K Offline
              KroMignon
              wrote on 2 Dec 2019, 16:02 last edited by KroMignon 12 Feb 2019, 16:03
              #6

              @ivanicy You can try something like this:

              GIT_DATE=$$system(git --git-dir $$PWD/.git --work-tree $$PWD log -n 1 --pretty=%cd --date=iso)
              DEFINES += GIT_DATE=\\\"$$GIT_DATE\\\"
              

              It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

              I 1 Reply Last reply 3 Dec 2019, 09:26
              0
              • S Offline
                S Offline
                SGaist
                Lifetime Qt Champion
                wrote on 2 Dec 2019, 21:33 last edited by
                #7

                Hi,

                Note that this escaping might not apply to all OSs (thinking about Windows).

                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
                • K KroMignon
                  2 Dec 2019, 16:02

                  @ivanicy You can try something like this:

                  GIT_DATE=$$system(git --git-dir $$PWD/.git --work-tree $$PWD log -n 1 --pretty=%cd --date=iso)
                  DEFINES += GIT_DATE=\\\"$$GIT_DATE\\\"
                  
                  I Offline
                  I Offline
                  ivanicy
                  wrote on 3 Dec 2019, 09:26 last edited by ivanicy 12 Mar 2019, 09:33
                  #8

                  @KroMignon I get "expected expression" error again when I try to use it. But I don't know why because It is used the same as the other.

                  I changed "$$PWD/.git" to "&&PWD\..\.git" because this is my git directory. This change works with the GIT_VERSION variable.

                  K 1 Reply Last reply 3 Dec 2019, 09:53
                  0
                  • I ivanicy
                    3 Dec 2019, 09:26

                    @KroMignon I get "expected expression" error again when I try to use it. But I don't know why because It is used the same as the other.

                    I changed "$$PWD/.git" to "&&PWD\..\.git" because this is my git directory. This change works with the GIT_VERSION variable.

                    K Offline
                    K Offline
                    KroMignon
                    wrote on 3 Dec 2019, 09:53 last edited by
                    #9

                    @ivanicy Good read, I have copy this from your previous post... but if you problem is solved, don't forget to mark this thread as solved too.

                    It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                    I 1 Reply Last reply 3 Dec 2019, 10:06
                    0
                    • K KroMignon
                      3 Dec 2019, 09:53

                      @ivanicy Good read, I have copy this from your previous post... but if you problem is solved, don't forget to mark this thread as solved too.

                      I Offline
                      I Offline
                      ivanicy
                      wrote on 3 Dec 2019, 10:06 last edited by
                      #10

                      @KroMignon But I am getting error with the GIT_DATE variable and I don't know why.

                      GIT_DATE = $$system(git --git-dir $$PWD\..\.git --work-tree $$PWD log -n 1 --pretty=%cd --date=iso)
                      DEFINES += GIT_DATE=\\\"$$GIT_DATE\\\"
                      

                      I get "expected expression"

                      840780ca-f716-496c-8540-548eb55f7f04-image.png

                      Thank you for your help

                      K 1 Reply Last reply 3 Dec 2019, 10:26
                      0
                      • I ivanicy
                        3 Dec 2019, 10:06

                        @KroMignon But I am getting error with the GIT_DATE variable and I don't know why.

                        GIT_DATE = $$system(git --git-dir $$PWD\..\.git --work-tree $$PWD log -n 1 --pretty=%cd --date=iso)
                        DEFINES += GIT_DATE=\\\"$$GIT_DATE\\\"
                        

                        I get "expected expression"

                        840780ca-f716-496c-8540-548eb55f7f04-image.png

                        Thank you for your help

                        K Offline
                        K Offline
                        KroMignon
                        wrote on 3 Dec 2019, 10:26 last edited by
                        #11

                        @ivanicy Have tried to search GIT_DATE= in the compilation output windows in QtCreator?

                        It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                        I 1 Reply Last reply 3 Dec 2019, 11:17
                        0
                        • K KroMignon
                          3 Dec 2019, 10:26

                          @ivanicy Have tried to search GIT_DATE= in the compilation output windows in QtCreator?

                          I Offline
                          I Offline
                          ivanicy
                          wrote on 3 Dec 2019, 11:17 last edited by
                          #12

                          @KroMignon In the Compile output GIT_DATE has the correct value. But when I try to use it, it is as if the variable was not recognized.

                          K 1 Reply Last reply 3 Dec 2019, 11:18
                          0
                          • I ivanicy
                            3 Dec 2019, 11:17

                            @KroMignon In the Compile output GIT_DATE has the correct value. But when I try to use it, it is as if the variable was not recognized.

                            K Offline
                            K Offline
                            KroMignon
                            wrote on 3 Dec 2019, 11:18 last edited by
                            #13

                            @ivanicy Can you show me what you see in the window?

                            It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                            I 1 Reply Last reply 3 Dec 2019, 11:21
                            0
                            • K KroMignon
                              3 Dec 2019, 11:18

                              @ivanicy Can you show me what you see in the window?

                              I Offline
                              I Offline
                              ivanicy
                              wrote on 3 Dec 2019, 11:21 last edited by
                              #14

                              @KroMignon Yes, of course. This is the GIT_DATE value in Compile Output window:

                              b219ecc7-b377-4e85-b67c-f6423e949699-image.png

                              K 1 Reply Last reply 3 Dec 2019, 11:31
                              0
                              • I ivanicy
                                3 Dec 2019, 11:21

                                @KroMignon Yes, of course. This is the GIT_DATE value in Compile Output window:

                                b219ecc7-b377-4e85-b67c-f6423e949699-image.png

                                K Offline
                                K Offline
                                KroMignon
                                wrote on 3 Dec 2019, 11:31 last edited by KroMignon 12 Mar 2019, 11:33
                                #15

                                @ivanicy I would suggest you to change you C++ as follow:

                                ui->labelVersion->setText(QString("Add (version %1)").arg(GIT_VERSION));
                                

                                Perhaps you can also try out other date formats in your PRO file:

                                GIT_DATE = $$system(git --git-dir $$PWD\..\.git --work-tree $$PWD log -n 1 --pretty=%cd --date=iso)
                                GIT_DATE = $$system(git --git-dir $$PWD\..\.git --work-tree $$PWD log -n 1 --pretty=%cI)
                                GIT_DATE = $$system(git --git-dir $$PWD\..\.git --work-tree $$PWD log -n 1 --pretty=%ci)
                                

                                Check git documentation ==> https://git-scm.com/docs/pretty-formats

                                It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                                1 Reply Last reply
                                0
                                • AndrewBindrawA Offline
                                  AndrewBindrawA Offline
                                  AndrewBindraw
                                  wrote on 26 Apr 2021, 08:14 last edited by
                                  #16

                                  Hi.
                                  Please, check my repo. Set Qt App version from git.

                                  https://github.com/mrbindraw/TestVersion

                                  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