PDA

View Full Version : Qt header files suggestion



chandan
1st March 2011, 09:54
Hi Everyone,
I am currently including different Qt header files in my classes. But most of them can be replaced by QtGui. Is it a good way of doing that or should I just leave them as it is?

Thanks.

Chandan

Lykurg
1st March 2011, 10:02
Well it is up to you. And in "normal" cases it not important. If you what to optimize size and speed of compilation use forward declarations where ever possible and use e.g.
#include <QtCore/QString>

chandan
1st March 2011, 10:11
Thanks for your help. Will this forward declaration will increase the time efficiency? I mean, currently I am writing an application which contains lots of customised widgets and dialogs and whenever I am changing any of their header files then the application takes 3-4 minutes to build. So if I use the forward declaration then will it decrease the build time?

Chandan

Lykurg
1st March 2011, 10:23
Simple example:
You have two header files a.h and b.h. b.h looks like
#ifndef _B_H
#define _B_H
#include "a.h"
class B
{
A* a;
};
#endif
So if you change something in a.h not only this needs to be recompiled, but also b.h. Otherwise (if you use forward declaration) only a.h needs to be recompiled. So yes, you can speed up compilation time.

#ifndef _B_H
#define _B_H
class A;
class B
{
A* a;
};
#endif
Also, the compiler has not to include the header file here, which also saves some time, but that is not much...