PDA

View Full Version : Proper way to #include Qt?



pherthyl
11th August 2006, 00:40
When I write Qt4 code, I just use the line
#include <QtGui>
in my header files to add basically everything I ever need. Then in my .cpp file I would just have
#include "myheader.h"

However, in the Qt examples, the header files often contain only a few specific #includes and then just the classes that are used in the header, like this:

#include <QDialog>
#include <QList>
class QHBoxLayout;
class QPushButton;

Then in their .cpp file they have something like:
#include <QtGui>
#include "myheader.h"

So my question is, why do they do it like this? It seems like a lot of extra lines of code for no advantage. Does it compile faster this way?

jacek
11th August 2006, 02:15
Does it compile faster this way?
Potentially, since compiler doesn't have to read half of Qt headers.