PDA

View Full Version : include



mickey
4th April 2006, 22:05
Hi, I have seen this line at the end of a main.cpp. What does this do? Thanks



//main.cpp
.........
#include "main.moc"

jacek
4th April 2006, 22:09
It tells qmake to run moc on this file and generate "main.moc" with implementation of the signals and slots mechanism. You must use it when you place class definition with Q_OBJECT macro in a .cpp file.

mickey
4th April 2006, 22:12
sorrry, but when do I need to put a class in main.ccp instead of in a apart file? thanks

jacek
4th April 2006, 22:15
sorrry, but when do I need to put a class in main.ccp instead of in a apart file? thanks
You put class definitions in .cpp file only when you don't want them to be visible outside that file.

mickey
4th April 2006, 22:19
but Is there a pratical reason to hide a class into a .cpp? Why to hide?
Thanks

jacek
4th April 2006, 22:31
but Is there a pratical reason to hide a class into a .cpp? Why to hide?For example when you are writing a library, you might want to hide the implementation, so that after every change you don't have to recompile all programs that use that library. Ask google about "pimpl" or "d pointer".

wysota
4th April 2006, 23:14
Or when you are lazy and don't want to create three files instead of one. :cool: