PDA

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



blue_sky
1st October 2013, 17:39
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+=.....

ChrisW67
2nd October 2013, 05:38
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.

blue_sky
2nd October 2013, 05:56
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?

anda_skoa
2nd October 2013, 10:45
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,
_

blue_sky
2nd October 2013, 13:57
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