PDA

View Full Version : Global include of a file



Momergil
18th July 2014, 13:47
Hello!

I'ld like to know if there is a way in Qt/qmake to command the inclusion of a given file (a header, in my case) in all files/headers/sources (a "global include") so avoiding having to set a #include "myfile.h" in all headers of my project (much like what a DEFINES in a .pro file makes when creating a definition that is valid for all files in the project).


Thanks,

Momergil

anda_skoa
18th July 2014, 15:42
Defines is passed as an argument to the compiler which then passes it on to its preprocessor.
I haven't heard about any compiler which provides a way to provide include directives to its preprocessor.

What do you need this for?

Cheers,
_

ChrisW67
18th July 2014, 22:10
GCC has an "-include" option that does this, but it is not quite the same as actually including the file.
http://stackoverflow.com/questions/3387453/include-header-files-from-command-line-gcc

For Microsoft's tools see http://msdn.microsoft.com/en-us/library/8c5ztk84.aspx

Isn't Google grand

Momergil
19th July 2014, 17:49
What do you need this for?

Cheers,
_


Well remember the QtGlobal namespace that is available in all files of a Qt-based project? (or at least a Qt Widgets one). Well I'ld like to do the same: create a namespace inside a .hpp and a .cpp and then make them available to all files of my project but without having to add a #include "mynamespace.h" at top of all those (dozens of) files :)


Thanks, Chris, for the answer!

Momergil

anda_skoa
19th July 2014, 23:27
Well remember the QtGlobal namespace that is available in all files of a Qt-based project? (or at least a Qt Widgets one). Well I'ld like to do the same: create a namespace inside a .hpp and a .cpp and then make them available to all files of my project but without having to add a #include "mynamespace.h" at top of all those (dozens of) files :)


Then why not do the same like qglobal.h if this is the effect you'd like to have.
They don't need any magic for that either.

Cheers,
_

Momergil
20th July 2014, 03:40
Then why not do the same like qglobal.h if this is the effect you'd like to have.


Well, and what would that be exactly? :X

Btw, I found this post (http://stackoverflow.com/questions/571568/is-there-a-way-to-include-a-header-in-every-compilation-unit-without-modifying-e?rq=1) in StackOverflow which quite answer the same question I posted :)


Thanks,

Momergil

anda_skoa
20th July 2014, 09:04
Well, and what would that be exactly? :X

Using C/C++ preprozessor #include directives.
If you do a file content search in the Qt sources, you'll find lots of them

Cheers,
_