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. Macro definition at runtime
QtWS25 Last Chance

Macro definition at runtime

Scheduled Pinned Locked Moved General and Desktop
macroruntime
5 Posts 3 Posters 1.8k 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.
  • J Offline
    J Offline
    Jessica
    wrote on 25 Aug 2015, 14:05 last edited by
    #1

    Hi,

    I'd like to define macros used in #ifdefs statements at runtime (environment variables) instead of compilation time. Is there a way to do that in Qt?

    Thanks

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 25 Aug 2015, 14:28 last edited by
      #2

      Hi and welcome to devnet,

      If you want to use environment variables content in your code take a look at qgetenv otherwise no, macros are pre-processed at build time (nothing Qt specific here it's how C/C++ works)

      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
      0
      • P Offline
        P Offline
        Pablo J. Rogina
        wrote on 25 Aug 2015, 14:29 last edited by
        #3

        @Jessica Do you mean reading environment variables at runtime and acting accordingly in your code? If so, I guess you may want to take a look at qgetenv function.

        Upvote the answer(s) that helped you solve the issue
        Use "Topic Tools" button to mark your post as Solved
        Add screenshots via postimage.org
        Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

        1 Reply Last reply
        0
        • J Offline
          J Offline
          Jessica
          wrote on 25 Aug 2015, 17:06 last edited by
          #4

          Thank you guys,

          qgetenv worked :)

          1 Reply Last reply
          0
          • P Offline
            P Offline
            Pablo J. Rogina
            wrote on 25 Aug 2015, 17:15 last edited by
            #5

            @Jessica you're welcomed. Please don't forget to mark the post as solved.

            Upvote the answer(s) that helped you solve the issue
            Use "Topic Tools" button to mark your post as Solved
            Add screenshots via postimage.org
            Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

            1 Reply Last reply
            0

            4/5

            25 Aug 2015, 17:06

            • Login

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