fonZ
fonZ

Reputation: 2479

Qt include files

I got into a discussion with somebody that tells me that it's not good to do what Qt does with include files because i adopted the same strategy in my code.

Let's use QApplication as an example, when you want to include QApplication then you should do:

#include <QApplication>

QApplication is a file without extension that contains:

#include "qapplication.h"

The only disadvantage is see is that it creates more files in the project. Besides that i think it only has advantages.

So my question is, why is this a good or a bad idea?

Upvotes: 3

Views: 3366

Answers (2)

L&#225;szl&#243; Papp
L&#225;szl&#243; Papp

Reputation: 53173

I think it is the matter of personal taste, mostly. Different projects use different style. Qt picked up this style.

1) It is basically partially matching the standard library includes without the header extension, although CamelCase. It is different in that regard though that the standard library does not allow these days to use the suffixed version.

2) It could also help with class includes within a header with a different main class. See this example:

#include <QFoo>

where QFoo is defined in qbar.h since the main class is QBar, but there is another class put into the same header.

The only disadvantage is see is that it creates more files in the project.

It does not create more files than needed because these could be generated on the fly like in the Qt Project. In that case, it does not clutter your source tree, and will be put into the build directory, or at least a separate place where it does not get in your way. This is done currently by syncqt in the Qt Project.

Upvotes: 3

Nejat
Nejat

Reputation: 32635

Using header files with no extension is not a good idea as it makes it difficult to search header files (*.h or *.hpp) and it makes it more difficult to identify the contents of a file (for example if your editor relies on the extension to choose the proper syntax highlighting mode). Also it causes to have more files in the project as you mentioned.

Also Qt uses that convention exactly because smart programmers don't. It means your headers won't clash with new Qt headers.

So i think using your header files with extensions separates your custom header files from Qt ones in some way. It makes it more clear and clean that which header is for Qt and which one is yours.

Upvotes: 2

Related Questions