Results 1 to 5 of 5

Thread: Difference between including a header file in a file(cpp/.h) and in a .pro file?

  1. #1
    Join Date
    Sep 2013
    Posts
    33
    Thanks
    5
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Exclamation Difference between including a header file in a file(cpp/.h) and in a .pro file?

    Generally when a .cpp or .h use information of other header, then we should include header in that file.But When the headers in pro file is added?
    i.e. HEADERS+=.....

  2. #2
    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: Difference between including a header file in a file(cpp/.h) and in a .pro file?

    Any header file from your project that contains Q_OBJECT or other Qt specific markers for the metaobject compiler (moc) should be listed in HEADERS so that qmake ensures moc is run on them.

  3. #3
    Join Date
    Sep 2013
    Posts
    33
    Thanks
    5
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Difference between including a header file in a file(cpp/.h) and in a .pro file?

    Quote Originally Posted by ChrisW67 View Post
    Any header file from your project that contains Q_OBJECT or other Qt specific markers for the metaobject compiler (moc) should be listed in HEADERS so that qmake ensures moc is run on them.
    So if my cpp need a header file, which contain Q_OBJECT , then I should include it in both cpp file as well as HEADER+= of pro file?

  4. #4
    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: Difference between including a header file in a file(cpp/.h) and in a .pro file?

    Yes, those two "inclusions" server different purposes.

    The include in the cpp file is necessary for the compiler to know about the types and functions declared in that header, in order for code in the cpp file to use them
    The adding to the HEADERS variable is necessary for Qt's MOC to process the Qt specific things inside the header, e.g. generate code for signal/slots

    The two inclusion points are totally unrelated.

    Cheers,
    _

  5. #5
    Join Date
    Sep 2013
    Posts
    33
    Thanks
    5
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Post Re: Difference between including a header file in a file(cpp/.h) and in a .pro file?

    Quote Originally Posted by anda_skoa View Post
    Yes, those two "inclusions" server different purposes.

    The include in the cpp file is necessary for the compiler to know about the types and functions declared in that header, in order for code in the cpp file to use them
    The adding to the HEADERS variable is necessary for Qt's MOC to process the Qt specific things inside the header, e.g. generate code for signal/slots

    The two inclusion points are totally unrelated.

    Cheers,
    _
    Thank you very much.. Got it

Similar Threads

  1. Migrating content from header file to source file
    By ehnuh in forum Qt Programming
    Replies: 2
    Last Post: 3rd October 2012, 18:00
  2. Replies: 2
    Last Post: 4th January 2012, 14:26
  3. Problem in file including.
    By Niamita in forum Qt Programming
    Replies: 5
    Last Post: 27th July 2011, 13:15
  4. Qt Creator PROBLEM INCLUDING 'QSystemInfo' HEADER FILE
    By Rakula in forum Qt Tools
    Replies: 1
    Last Post: 24th September 2010, 10:28
  5. Replies: 3
    Last Post: 25th May 2007, 08:49

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.