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. Changing qmake/.pro file with cpp files

Changing qmake/.pro file with cpp files

Scheduled Pinned Locked Moved Unsolved General and Desktop
14 Posts 4 Posters 1.9k Views
  • 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.
  • G Offline
    G Offline
    GCDX
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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 ?

      1 Reply Last reply
      2
      • G Offline
        G Offline
        GCDX
        wrote on last edited by
        #3

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

        However, it is still rather vague to me, could you give me an example on how it is done? Thanks so much.

        1 Reply Last reply
        0
        • G Offline
          G Offline
          GCDX
          wrote on last edited by
          #4

          So basically, i want to use override the DEFINE statement in the qmake file by running a script?? Could you give me a structure on how to run the script? Cause i do not know the syntax :(

          mrjjM 1 Reply Last reply
          0
          • G GCDX

            So basically, i want to use override the DEFINE statement in the qmake file by running a script?? Could you give me a structure on how to run the script? Cause i do not know the syntax :(

            mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by mrjj
            #5

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

            1 Reply Last reply
            3
            • G Offline
              G Offline
              GCDX
              wrote on last edited by
              #6

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

              aha_1980A mrjjM 2 Replies Last reply
              0
              • G GCDX

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

                aha_1980A Offline
                aha_1980A Offline
                aha_1980
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @GCDX said in Changing qmake/.pro file with cpp files:

                $$system

                http://doc.qt.io/archives/qt-4.8/qmake-function-reference.html#system-command

                Qt has to stay free or it will die.

                1 Reply Last reply
                1
                • G GCDX

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

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

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

                  G 1 Reply Last reply
                  1
                  • mrjjM mrjj

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

                    G Offline
                    G Offline
                    GCDX
                    wrote on last edited by
                    #9

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

                    1 Reply Last reply
                    0
                    • G Offline
                      G Offline
                      GCDX
                      wrote on last edited by
                      #10

                      @mrjj Right now it runs the time.cpp. However, it does not allow BUILD_TIME to assign a new value

                      mrjjM 1 Reply Last reply
                      0
                      • G GCDX

                        @mrjj Right now it runs the time.cpp. However, it does not allow BUILD_TIME to assign a new value

                        mrjjM Offline
                        mrjjM Offline
                        mrjj
                        Lifetime Qt Champion
                        wrote on last edited by
                        #11

                        @GCDX

                        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.

                        1 Reply Last reply
                        0
                        • SGaistS Offline
                          SGaistS Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on last edited by
                          #12

                          Hi,

                          Why hardcode the key ? You could make a settings of it for your application.

                          Interested in AI ? www.idiap.ch
                          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                          G 1 Reply Last reply
                          1
                          • SGaistS SGaist

                            Hi,

                            Why hardcode the key ? You could make a settings of it for your application.

                            G Offline
                            G Offline
                            GCDX
                            wrote on last edited by
                            #13

                            @SGaist Could you elaborate on this? And if possible show me documentation as well? Because i tried to declare it as a public variable but it couldn't be accessed outside of the class. I was wondering if there is a better way?

                            1 Reply Last reply
                            0
                            • SGaistS Offline
                              SGaistS Offline
                              SGaist
                              Lifetime Qt Champion
                              wrote on last edited by
                              #14

                              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.

                              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
                              0

                              • Login

                              • Login or register to search.
                              • First post
                                Last post
                              0
                              • Categories
                              • Recent
                              • Tags
                              • Popular
                              • Users
                              • Groups
                              • Search
                              • Get Qt Extensions
                              • Unsolved