Current year in Qt pro file
Hi! I want to get current year in qt pro file to display it in QMAKE_TARGET_COPYRIGHT variable.
I have tried with $$system("date") but it doesn't work.
How to do it? Thanks in advance.
What is your code exactly ?
QMAKE_TARGET_COPYRIGHT = $$system("date /T") message($$QMAKE_TARGET_COPYRIGHT)
Project MESSAGE: Fri 02/17/2017
When I use just
$$system("date")it can't read the Qt project.
I need to pass some parameter to get just - 2017.
@Cobra91151 What about
see: man date
Update: you're on Windows?
I have tried your code:
QMAKE_TARGET_COPYRIGHT = $$system("date +%Y") message($$QMAKE_TARGET_COPYRIGHT)
After pro file is saved it can't read my project. It stuck on - Reading Project....
Also I have tried to create console application to test it. If I'm right that $$system() function in Qt is the same as is system() (C++) when use it in Visual Studio project. So:
Visual Studio Console Project Code:
system("date") - returns: The current date is: Fri 02/17/2017 (not working in Qt pro)
system("date /T") - returns: Fri 02/17/2017 (working in Qt pro)
So I think system("date /T") should be, but I need also some parameter to display just year.
well date +%Y does
so that is why its hanging :)
Date command do not mention ANY way to change the format. ( in help)
So there no way to get current year in QMAKE_TARGET_COPYRIGHT?
I have found a solution. Code:
QMAKE_TARGET_COPYRIGHT = $$system("echo %date:~10,4%")
It returns 2017.
since the length should remain the same, cutting should work
across languages etc. i hope.
@Cobra91151 date +%Y is for Linux, that's why I asked about Windows :-)