Results 1 to 7 of 7

Thread: Global include of a file

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2011
    Location
    Porto Alegre, Brazil
    Posts
    482
    Thanks
    165
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Global include of a file

    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
    May the Lord be with you. Always.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Global include of a file

    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,
    _

  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Global include of a file

    GCC has an "-include" option that does this, but it is not quite the same as actually including the file.
    http://stackoverflow.com/questions/3...mmand-line-gcc

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

    Isn't Google grand
    Last edited by ChrisW67; 18th July 2014 at 22:11. Reason: updated contents

  4. The following user says thank you to ChrisW67 for this useful post:

    Momergil (19th July 2014)

  5. #4
    Join Date
    Jun 2011
    Location
    Porto Alegre, Brazil
    Posts
    482
    Thanks
    165
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Global include of a file

    Quote Originally Posted by anda_skoa View Post
    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
    May the Lord be with you. Always.

  6. #5
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Global include of a file

    Quote Originally Posted by Momergil View Post
    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,
    _

  7. #6
    Join Date
    Jun 2011
    Location
    Porto Alegre, Brazil
    Posts
    482
    Thanks
    165
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Global include of a file

    Quote Originally Posted by anda_skoa View Post
    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 in StackOverflow which quite answer the same question I posted


    Thanks,

    Momergil
    May the Lord be with you. Always.

  8. #7
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Global include of a file

    Quote Originally Posted by Momergil View Post
    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,
    _

  9. The following user says thank you to anda_skoa for this useful post:

    Momergil (20th July 2014)

Similar Threads

  1. Replies: 2
    Last Post: 21st March 2014, 18:53
  2. Replies: 2
    Last Post: 3rd August 2012, 06:31
  3. Replies: 1
    Last Post: 23rd May 2011, 04:53
  4. Replies: 3
    Last Post: 1st November 2010, 16:33
  5. Replies: 4
    Last Post: 9th May 2010, 16:18

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.