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. Environment variables

Environment variables

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 4 Posters 2.5k 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.
  • U Offline
    U Offline
    UHaider
    wrote on last edited by
    #1

    Hi,

    My Qt application uses multiple text files. I want my application executable to be placed in a directory that is specified by the user and the text files can be placed in some other directory.
    How can I control this using flags e.g. qmake -executable_director -text_files_directory and then use text_files_directory in my code to read the text files? Basically I want to give user the privilege to specify where the executable is placed and where the text files should be placed while building/installing the application. I wish I could be more clearer :(

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

      Hi,

      Do you mean you want run time and build time environment variables ?

      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
      • U Offline
        U Offline
        UHaider
        wrote on last edited by
        #3

        Thanks for your reply. Let me explain again please.

        I made an application using QT creator and its running fine. When I run the application it does following

        • list itemReads some text files {File1,File2...,FileN} from the directory MY_DIR=/home/develop/Documents/

        • list itemExecutable is placed in EXE_DIR=default directory of project

        In my code the variable MY_DIR is set to /home/develop/Documents/. Now I want to allow the user to set the value of MY_DIR while building/installing the application without QT creator and use that value in my source code.
        So, I want to install this application on a PC that has no QT creator but QT installed. I want to make a script that can be used to

        • list itembuild\install the application

        • list itemSet the value of MY_DIR and EXE_DIR.

        • list itemCopies text files {File1,File2...,FileN} from source directory to MY_DIR

        • list itemPlaces the executable in EXE_DIR.

        Some things like this

        qmake -MY_DIR=/usr/local/lib/text_files -EXE_DIR=/usr/bin

        In my source code

        Qsettings* genSettings;
        genSettings = new Qsettings(MY_DIR+"/File1", QSettings::IniFormat);

        jsulmJ 1 Reply Last reply
        0
        • U UHaider

          Thanks for your reply. Let me explain again please.

          I made an application using QT creator and its running fine. When I run the application it does following

          • list itemReads some text files {File1,File2...,FileN} from the directory MY_DIR=/home/develop/Documents/

          • list itemExecutable is placed in EXE_DIR=default directory of project

          In my code the variable MY_DIR is set to /home/develop/Documents/. Now I want to allow the user to set the value of MY_DIR while building/installing the application without QT creator and use that value in my source code.
          So, I want to install this application on a PC that has no QT creator but QT installed. I want to make a script that can be used to

          • list itembuild\install the application

          • list itemSet the value of MY_DIR and EXE_DIR.

          • list itemCopies text files {File1,File2...,FileN} from source directory to MY_DIR

          • list itemPlaces the executable in EXE_DIR.

          Some things like this

          qmake -MY_DIR=/usr/local/lib/text_files -EXE_DIR=/usr/bin

          In my source code

          Qsettings* genSettings;
          genSettings = new Qsettings(MY_DIR+"/File1", QSettings::IniFormat);

          jsulmJ Online
          jsulmJ Online
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @UHaider You should not hard code such paths in your code! Especially not if your users are not going to build the software by themselves.
          Such configuration is usually done using config files on UNIX/Linux or registry on Windows. For that you should take a look at QSettings http://doc.qt.io/qt-5/qsettings.html
          That means this MY_DIR would be just a setting which can be changed by user and which will be read by your application at runtime.

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          U 1 Reply Last reply
          4
          • mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Hi
            Normally the location of the installed exe and location of data files are selected in the installer.
            You can also offer a menu to point to a new location in the app for the data files.
            And as @jsulm says, it should not be compiled into the .exe but kept as a setting externally.

            1 Reply Last reply
            2
            • jsulmJ jsulm

              @UHaider You should not hard code such paths in your code! Especially not if your users are not going to build the software by themselves.
              Such configuration is usually done using config files on UNIX/Linux or registry on Windows. For that you should take a look at QSettings http://doc.qt.io/qt-5/qsettings.html
              That means this MY_DIR would be just a setting which can be changed by user and which will be read by your application at runtime.

              U Offline
              U Offline
              UHaider
              wrote on last edited by
              #6

              @jsulm thanks for your reply. I think I was not clear. The users are going to build the software themselves. That is why I want to pass it like an argument to qmake and then read that value in source code.

              jsulmJ 1 Reply Last reply
              0
              • U UHaider

                @jsulm thanks for your reply. I think I was not clear. The users are going to build the software themselves. That is why I want to pass it like an argument to qmake and then read that value in source code.

                jsulmJ Online
                jsulmJ Online
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @UHaider Something like this:

                qmake DEFINES+='MY_DIR "PATH"'
                

                ?

                https://forum.qt.io/topic/113070/qt-code-of-conduct

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

                  Even if they build it themselves, hardcoding such values is no a good idea. QStandardPaths, QCoreApplication::applicationDirPath and QCommandLineParser. are better suited to get the files you want from when running your application.

                  Install target would be a good place to say where you want your application to be installed.

                  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