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. [Solved] Managing environment variables

[Solved] Managing environment variables

Scheduled Pinned Locked Moved General and Desktop
8 Posts 4 Posters 2.2k Views 3 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.
  • Joel BodenmannJ Offline
    Joel BodenmannJ Offline
    Joel Bodenmann
    wrote on last edited by Joel Bodenmann
    #1

    Is there anything that Qt offers to manage application wide environment variables?
    I am talking about variables that the user controls inside of the application which aren't related to anything outside of the application.

    Right now all I do is having a QMap<QString, QString> inside my preferences class which I pass around all the objects that need to access the environment variables.

    Is there a better solution to this?

    Industrial process automation software: https://simulton.com
    Embedded Graphics & GUI library: https://ugfx.io

    1 Reply Last reply
    0
    • D Offline
      D Offline
      deleted587
      wrote on last edited by
      #2

      Since QCoreApplication derives from QObject, you could use it's property and setProperty functions. Then, you wouldn't need to constantly pass around a "properties" data structure, just include the QApplication header file and use the qApp global pointer.

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

        Hi,

        What kind of "environment variables" do you have in mind ? Application settings ?

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

        Joel BodenmannJ 1 Reply Last reply
        0
        • C Offline
          C Offline
          code_fodder
          wrote on last edited by
          #4

          You can define some system-wide macros in your .pro file, for example:
          DEFINES += TEST1=1
          DEFINES += TEST2=2

          Or you can just use normal c style globals.

          Or you can use c++ style singleton global class with your parameters.

          It may help to know what kind of data you want to use

          1 Reply Last reply
          0
          • SGaistS SGaist

            Hi,

            What kind of "environment variables" do you have in mind ? Application settings ?

            Joel BodenmannJ Offline
            Joel BodenmannJ Offline
            Joel Bodenmann
            wrote on last edited by
            #5

            @SGaist Not application settings. More stuff like library paths. The users can submit different libraries of components he is using inside of the application. He can use environment variables to give a base path for all libraries: $(LIB_ROOT)/library1.
            But this is all only internal in the application and has nothing to do with the actual system the application is running on. It is something the user controls to abstract paths and other things.

            Industrial process automation software: https://simulton.com
            Embedded Graphics & GUI library: https://ugfx.io

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

              For environment variables (like PATH if I understand you correctly), you can use qgetenv

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

              Joel BodenmannJ 1 Reply Last reply
              0
              • SGaistS SGaist

                For environment variables (like PATH if I understand you correctly), you can use qgetenv

                Joel BodenmannJ Offline
                Joel BodenmannJ Offline
                Joel Bodenmann
                wrote on last edited by
                #7

                @SGaist I am more talking about PATHs that are only used INSIDE of my application that have nothing to do with the external world. Environment variables that hold paths to binaries, libraries etc. Nothing the underlying operating system is aware of. It is only internal to my application.

                Industrial process automation software: https://simulton.com
                Embedded Graphics & GUI library: https://ugfx.io

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

                  Then use a central object that provides these values. You can make it a singleton to ensure there's only one 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

                  1 Reply Last reply
                  1

                  • Login

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