Changing qmake/.pro file with cpp files
-
Hello,
i'm trying to parse information from a webpage and override a file in my .pro file? I don't seem to be able to find a solution.Basically, im debugging a program whereby I need to change an API key through a c++ parsing file and overriding the .pro APIKEY definition. This is to ensure that different API keys will poll from the server instead of just one, preventing overloading of server. So just wondering if anyone can help me and point me in the right direction to use this
-
Hi
You can execute app/script from .pro file
with $$system()but not sure how you want it to work.
like get new key on every compile or what rules are.do you already have the app that parses the page and get keys ?
-
@mrjj Yes i want every user that downloads the exe file to be able to (one-time only) have some information such as an API key unique to all users to be put into the .pro file.
I found information such as http://doc.qt.io/archives/qt-4.8/qmake-function-reference.html#system-command
https://stackoverflow.com/questions/3612283/running-a-program-script-from-qmakeHowever, it is still rather vague to me, could you give me an example on how it is done? Thanks so much.
-
@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.