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. How to declare a global changeable variable?
Forum Updated to NodeBB v4.3 + New Features

How to declare a global changeable variable?

Scheduled Pinned Locked Moved Solved General and Desktop
22 Posts 5 Posters 15.9k Views 1 Watching
  • 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

    @JonB It needs an API key. However, the problem is that if too many use the API key it will be a threat to the server and the API key will get banned

    JonBJ Offline
    JonBJ Offline
    JonB
    wrote on last edited by
    #12

    @GCDX
    I can only imagine this means: at present there is a DEFINE for a constant number/string for some "API key", and you want to change that to be a variable which can be assigned at runtime (somehow) so that it can vary.

    G 1 Reply Last reply
    0
    • JonBJ JonB

      @GCDX
      I can only imagine this means: at present there is a DEFINE for a constant number/string for some "API key", and you want to change that to be a variable which can be assigned at runtime (somehow) so that it can vary.

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

      @JonB Yes, i want it to change such that every user who downloads the app can generate their own API key so a single API key won't be the one polling the system

      JonBJ 1 Reply Last reply
      0
      • G GCDX

        @JonB Yes, i want it to change such that every user who downloads the app can generate their own API key so a single API key won't be the one polling the system

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by JonB
        #14

        @GCDX
        Then you do indeed need to change over from the DEFINE to a variable! (The existing DEFINE is not a "static global variable", it's a [pre-processor] constant, which is quite different.)

        G 1 Reply Last reply
        1
        • JonBJ JonB

          @GCDX
          Then you do indeed need to change over from the DEFINE to a variable! (The existing DEFINE is not a "static global variable", it's a [pre-processor] constant, which is quite different.)

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

          @JonB Yes its global variable using extern in a globalvariable.h file.

          mrjjM 1 Reply Last reply
          0
          • G GCDX

            @JonB Yes its global variable using extern in a globalvariable.h file.

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

            @GCDX
            And you also need to save it to a file or will user generate new each time?

            G 1 Reply Last reply
            0
            • mrjjM mrjj

              @GCDX
              And you also need to save it to a file or will user generate new each time?

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

              @mrjj do i need to use QFileDialog for this??

              JonBJ mrjjM 3 Replies Last reply
              0
              • G GCDX

                @mrjj do i need to use QFileDialog for this??

                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by JonB
                #18

                @GCDX
                Read up on http://doc.qt.io/qt-5/qsettings.html#details for an explanation (including sub-topic Platform-Specific Notes). In the usual case, you do not ask the user where to save the settings (your QFileDialog), you allow Qt to save it in the "default" place for your OS.

                QSettings automatically saves your changes for you.

                [EDIT: I'm not sure why I started talking about QSettings here, I thought you/@mrjj had mentioned it, but perhaps not --- I may have been getting mixed up with another question I was answering! Nonetheless, it's a possible way of saving something to file if that's what you want...]

                1 Reply Last reply
                0
                • G GCDX

                  @mrjj do i need to use QFileDialog for this??

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

                  @GCDX
                  Only if user should select file name himself.
                  else you will just save it using QFile to a writable location , you can find lookup using
                  http://doc.qt.io/qt-5/qstandardpaths.html

                  1 Reply Last reply
                  1
                  • G GCDX

                    @mrjj do i need to use QFileDialog for this??

                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on last edited by
                    #20

                    @GCDX
                    If you ask the user for a file name/path to save to, you are going to have to ask the user for the same path in order to read it back at a later date. This does not sound likely! More like @mrjj's suggestion of saving to a standard file name in a standard directory so that you can re-read it subsequently automatically.

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

                      @JonB @mrjj Hmm this is interesting, however, i read the QSettings documentation and i am a little confused. How does QSettings store a permanent change? If not shouldn't i used QSettings instead of the extern global variable??

                      mrjjM 1 Reply Last reply
                      0
                      • G GCDX

                        @JonB @mrjj Hmm this is interesting, however, i read the QSettings documentation and i am a little confused. How does QSettings store a permanent change? If not shouldn't i used QSettings instead of the extern global variable??

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

                        @GCDX
                        QSetting could also be used. Not a bad idea.
                        On linux it stores in a ini file pr default. on Windows , in registry.

                        https://wiki.qt.io/How_to_Use_QSettings

                        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