Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Unsolved Changing qmake/.pro file with cpp files

    General and Desktop
    4
    14
    1136
    Loading More Posts
    • 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
      GCDX last edited by

      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 Reply Quote 0
      • mrjj
        mrjj Lifetime Qt Champion last edited by

        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 Reply Quote 2
        • G
          GCDX last edited by

          @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 Reply Quote 0
          • G
            GCDX last edited by

            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 :(

            mrjj 1 Reply Last reply Reply Quote 0
            • mrjj
              mrjj Lifetime Qt Champion @GCDX last edited by mrjj

              @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 Reply Quote 3
              • G
                GCDX last edited by

                @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_1980 mrjj 2 Replies Last reply Reply Quote 0
                • aha_1980
                  aha_1980 Lifetime Qt Champion @GCDX last edited by

                  @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 Reply Quote 1
                  • mrjj
                    mrjj Lifetime Qt Champion @GCDX last edited by

                    @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 Reply Quote 1
                    • G
                      GCDX @mrjj last edited by

                      @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 Reply Quote 0
                      • G
                        GCDX last edited by

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

                        mrjj 1 Reply Last reply Reply Quote 0
                        • mrjj
                          mrjj Lifetime Qt Champion @GCDX last edited by

                          @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 Reply Quote 0
                          • SGaist
                            SGaist Lifetime Qt Champion last edited by

                            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 Reply Quote 1
                            • G
                              GCDX @SGaist last edited by

                              @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 Reply Quote 0
                              • SGaist
                                SGaist Lifetime Qt Champion last edited by

                                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 Reply Quote 0
                                • First post
                                  Last post