Changing qmake/.pro file with cpp files
-
@GCDX
Hi
example.win32 { BUILD_TIME = $$system("time /T") # no spaces between 'system' command and args. } else { BUILD_TIME = $$system("date") } message($$BUILD_TIME) # output the current time DEFINES+=BUILD_TIME # make it into a define to be used in app.
Time would be a script to get key.
-
@mrjj Thanks so much for clarifying the syntax with me!
However, do you have a link to help me understand what is happening here?
i assume win32 is when its a windows computer, but what does this mean $$system("time /T")? is it time.cpp that is the script that has to be created in the sources directory? And if it's time.cpp, do i use:
#include <iostream>
using namespace std;
int main(){
BUILD_TIME=101010;
return 0;
}
Because i tried this and i couldn't do it! Thanks so much for your time. -
-
@GCDX
Hi
the time /T just returns a time string. ( try in a cmd prompt)
it then sets this result to the variable BUILD_TIME
its then added
DEFINES+=
to the defines compiled into the program.
You can then read from app.
You can not actually set it from the app.
I imagine "time" would be your getkey.bat that would return a key
and have the compiled into app. Maybe i misread what goal is. -
@mrjj
win32 {
BUILD_TIME = $$system("time.cpp /T") to run a time.cpp file in the source directory
} else {
BUILD_TIME = $$system("date")
}
message($$BUILD_TIME) # output the current time
DEFINES+=BUILD_TIME # make it into a define to be used in app.I want the time.cpp file to update the define of the BUILD_TIME, so maybe in time.cpp it has a BUILD_TIME=100; however, it is still throwing me an error that lvalue required for left assignment of operand.
-
Not from inside the app. its a define.
From the project that needs to key key to its .pro file
you call some getkey.bat that returns the key.
that key is compiled into the app via the define from its .pro file.
If you need some other way of working, you need to adjust who set is and who reads it. -
Hi,
Why hardcode the key ? You could make a settings of it for your application.
-
QSettings comes to mind for example.
Where do you need to use that key in your code ?
If you have a class dedicated to the use of the API, then there's no need for a "public accessible from everywhere variable". Make the API key a property of that class and have a preference widget connected to the instance of that class what will update the API key. Then show that preference widget were appropriate to edit the key.