Solved GIT_VERSION variable in .pro
-
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!
-
@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 -
@KroMignon Thank you very much!!
-
@ivanicy your welcome ;) Don't forget to mark as solved!
-
@KroMignon And do you know how can I add the git date to this string?
-
@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\\\"
-
Hi,
Note that this escaping might not apply to all OSs (thinking about Windows).
-
@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.
-
@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.
-
@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"
Thank you for your help
-
@ivanicy Have tried to search GIT_DATE= in the compilation output windows in QtCreator?
-
@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.
-
@ivanicy Can you show me what you see in the window?
-
@KroMignon Yes, of course. This is the GIT_DATE value in Compile Output window:
-
@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
-
Hi.
Please, check my repo. Set Qt App version from git.