Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Global include

    General and Desktop
    4
    5
    3032
    Loading More Posts
    • 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
      readbooks last edited by

      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 Reply Quote 0
      • T
        twsimpson last edited by

        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 Reply Quote 0
        • R
          readbooks last edited by

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

          1 Reply Last reply Reply Quote 0
          • B
            broadpeak last edited by

            [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 Reply Quote 0
            • T
              tobias.hunger last edited by

              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 Reply Quote 0
              • First post
                Last post