[Development] Prefix includes with module name
olivier at woboq.com
Wed Nov 6 12:55:52 CET 2013
On Wednesday 06 November 2013 12:43:16 Kurt Pattyn wrote:
> What is the general rule to include files in a Qt add-on module, more
> specific, when should include files be prefixed with the module name?
> If I look at QTcpSocket.h I see:
> #include <QtNetwork/qabstractsocket.h>
> #include <QtCore/qvariant.h>
> Includes prefixed with the module name.
> In QTcpSocket.cpp:
> #include “qtcpsocket.h”
> #include “qtcpsocket_p.h”
> #include “qlist.h”
> #include “qhostaddress.h”
> Includes not prefixed.
> If I look at qdbusabstractadaptor.cpp:
> #include <QtCore/qcoreapplication.h>
> #include <QtCore/qset.h>
> #include “qdbusabstractadaptor.h”
> Includes not related to the dbus adaptor are prefixed with the QtCore module
> name, the other is not prefixed.
> Sometimes private header files are included prefixed with private
> (private/…_p.h), sometimes not.
> Is there a general rule, best practice to follow for include files when
> implementing a module or add-on for Qt?
In public header files, you must include the module name:
The rationale is that then users only need to specify the root include path
(if that's not already /usr/include) when compiling, and not every single sub
modules include paths.
Other than that, there is no real rules.
The private header from other sub-directories need to specify the "private/".
In QtCreator, one does not include the module name so it compiles both with
Qt4 and Qt5 despite the move to QtWidgets.
Just follow the convention of the file you modify.
Woboq - Qt services and support - http://woboq.com - http://code.woboq.org
More information about the Development