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.
  • ivanicyI ivanicy

    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!

    KroMignonK Offline
    KroMignonK Offline
    KroMignon
    wrote on 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)

    ivanicyI 2 Replies Last reply
    4
    • KroMignonK KroMignon

      @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

      ivanicyI Offline
      ivanicyI Offline
      ivanicy
      wrote on last edited by
      #3

      @KroMignon Thank you very much!!

      KroMignonK 1 Reply Last reply
      0
      • ivanicyI ivanicy

        @KroMignon Thank you very much!!

        KroMignonK Offline
        KroMignonK Offline
        KroMignon
        wrote on 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
        • KroMignonK KroMignon

          @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

          ivanicyI Offline
          ivanicyI Offline
          ivanicy
          wrote on last edited by
          #5

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

          KroMignonK 1 Reply Last reply
          0
          • ivanicyI ivanicy

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

            KroMignonK Offline
            KroMignonK Offline
            KroMignon
            wrote on last edited by KroMignon
            #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)

            ivanicyI 1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on 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
              • KroMignonK KroMignon

                @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\\\"
                
                ivanicyI Offline
                ivanicyI Offline
                ivanicy
                wrote on last edited by ivanicy
                #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.

                KroMignonK 1 Reply Last reply
                0
                • ivanicyI ivanicy

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

                  KroMignonK Offline
                  KroMignonK Offline
                  KroMignon
                  wrote on 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)

                  ivanicyI 1 Reply Last reply
                  0
                  • KroMignonK KroMignon

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

                    ivanicyI Offline
                    ivanicyI Offline
                    ivanicy
                    wrote on 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

                    KroMignonK 1 Reply Last reply
                    0
                    • ivanicyI ivanicy

                      @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

                      KroMignonK Offline
                      KroMignonK Offline
                      KroMignon
                      wrote on 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)

                      ivanicyI 1 Reply Last reply
                      0
                      • KroMignonK KroMignon

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

                        ivanicyI Offline
                        ivanicyI Offline
                        ivanicy
                        wrote on 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.

                        KroMignonK 1 Reply Last reply
                        0
                        • ivanicyI ivanicy

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

                          KroMignonK Offline
                          KroMignonK Offline
                          KroMignon
                          wrote on 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)

                          ivanicyI 1 Reply Last reply
                          0
                          • KroMignonK KroMignon

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

                            ivanicyI Offline
                            ivanicyI Offline
                            ivanicy
                            wrote on 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

                            KroMignonK 1 Reply Last reply
                            0
                            • ivanicyI ivanicy

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

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

                              KroMignonK Offline
                              KroMignonK Offline
                              KroMignon
                              wrote on last edited by KroMignon
                              #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 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