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. Global include
QtWS25 Last Chance

Global include

Scheduled Pinned Locked Moved General and Desktop
5 Posts 4 Posters 3.4k 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.
  • R Offline
    R Offline
    readbooks
    wrote on last edited by
    #1

    Hi,

    I have a constant file (constant.h ) and I want to include it in all my files without writing: #include "constant.h" everywhere. Is it possible to do it in Qt Creator, and if yes, how to do it.

    Thanks!

    1 Reply Last reply
    0
    • T Offline
      T Offline
      twsimpson
      wrote on last edited by
      #2

      That's not really possible, as the compiler must be able to see the contents of each include. So you do need to actually #include it for the compiler to see, and use, it.

      1 Reply Last reply
      0
      • R Offline
        R Offline
        readbooks
        wrote on last edited by
        #3

        Qt Creator hasn't an option to auto include the constant file in each file?

        1 Reply Last reply
        0
        • B Offline
          B Offline
          broadpeak
          wrote on last edited by
          #4

          [quote author="readbooks" date="1347296539"]Qt Creator hasn't an option to auto include the constant file in each file?[/quote]

          No, you must include it in every file where you use these constants.
          This is an C++ issue and not Qt (Creator) related.

          1 Reply Last reply
          0
          • T Offline
            T Offline
            tobias.hunger
            wrote on last edited by
            #5

            No, Qt Creator does not have such an option. There is a reasons for this:

            We want projects to be usable for people that do not want to use creator for whatever (obviously misguided;-) reasons. So we can not put options that need to be applied for every build into Creator. Those need to go into the build system.

            So why don't we add code into your build system for you? Doing so will limit which compilers can be used to build your project. Which compilers need to be supported is a decision the project-team has to make. We do not want creator to take away decisions from the developers.

            You can do this manually by adding code into the .pro-files (or CMakeLists.txt or whatever you use;-).

            It is pretty straight forward: You just need to check for compilers used and add the appropriate flags (check the documentation for those).

            The following code sets some compiler specific flags for qmake based project (default kind of project in Creator):

            @
            g++:QMAKE_CXXFLAGS += -Wall -Werror
            clang:QMAKE_CXXFLAGS += -Wall -Werror -Wno-something
            icc:QMAKE_CXXFLAGS += -Wall -Werror -Wno-something-else
            @

            (Note: Brain to terminal, untested)

            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