Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. How to analyze a KIT environment variable
QtWS25 Last Chance

How to analyze a KIT environment variable

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
qt 5creatorunixembedded linux
8 Posts 4 Posters 1.1k 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.
  • M Offline
    M Offline
    Michael65589
    wrote on 8 Jul 2020, 09:26 last edited by
    #1

    Hi,
    I want to use one QT application with two different KITs. One is for Linux (Ubuntu 18.04) and the other is for an embedded System (ARM).
    Therefore I have to switch the include paths in the .pro file.
    I set an environment variable in every KIT called TARGET. How can I create a if condition inside the .pro file? Or is there a possibility to use it like the standard defines unix, macx?

    Thanks

    1 Reply Last reply
    0
    • S Offline
      S Offline
      sierdzio
      Moderators
      wrote on 8 Jul 2020, 12:45 last edited by
      #2

      The contains function should do the job.

      Although more standard approach is to modify the behaviour of qmake using CONFIG instead.

      contains(YOUR_ENV_VAR, "someValue") {
        message("The variable contains some value")
      }
      

      Remember to change your env. var name from TARGET to something other - TARGET is already a keyword in qmake.

      (Z(:^

      1 Reply Last reply
      1
      • M Offline
        M Offline
        Michael65589
        wrote on 8 Jul 2020, 14:15 last edited by
        #3

        Hi sierdzio,
        thanks for the fast reply but it doesn't work for me. I changed the Variable to TESTVAR=EMBEDDED and add the following line to .pro file:

        contains(TESTVAR,EMBEDDED) {
        INCLUDEDIR += ...
        }

        I also tried contains($TESTVAR,EMBEDDED) and contains(TESTVAR,"EMBEDDED") and contains($TESTVAR,"EMBEDDED") but nothing works.

        Where is my mistake?

        1 Reply Last reply
        0
        • S Offline
          S Offline
          sierdzio
          Moderators
          wrote on 8 Jul 2020, 16:04 last edited by
          #4

          Perhaps this will:

          LOCAL_VAR=$$(YOUR_ENV_VAR)
          contains(LOCAL_VAR, "EMBEDDED") {
            INCLUDEDIR += ...
          }
          

          (Z(:^

          1 Reply Last reply
          0
          • M Offline
            M Offline
            Michael65589
            wrote on 9 Jul 2020, 05:31 last edited by
            #5

            Ah that was my mistake. I have to set a local variable to use the contains command.
            Okay that's the way I can use the environment variable inside the .pro file. How can I access the environment variable inside a .cpp file? With a #if directive?

            1 Reply Last reply
            0
            • H Offline
              H Offline
              hskoglund
              wrote on 9 Jul 2020, 05:50 last edited by
              #6

              Hi, in a .cpp file you can use getenv(), like this:

              QString target = getenv("TARGET");
              
              S 1 Reply Last reply 9 Jul 2020, 12:26
              2
              • M Offline
                M Offline
                Michael65589
                wrote on 9 Jul 2020, 06:22 last edited by
                #7

                That's it.
                Thanks a lot

                1 Reply Last reply
                0
                • H hskoglund
                  9 Jul 2020, 05:50

                  Hi, in a .cpp file you can use getenv(), like this:

                  QString target = getenv("TARGET");
                  
                  S Offline
                  S Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 9 Jul 2020, 12:26 last edited by
                  #8

                  @hskoglund said in How to analyze a KIT environment variable:

                  Hi, in a .cpp file you can use getenv(), like this:

                  QString target = getenv("TARGET");
                  

                  Or qEnvironmentVariable which returns a QString.

                  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

                  8/8

                  9 Jul 2020, 12:26

                  • Login

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