Qt #include forms

Thiago Macieira thiago at kde.org
Tue Mar 28 19:30:37 BST 2006


Joshua J. Berry wrote:
>Recommended for KDE, or for Qt?
>
>I'm just a Qt4 newbie, but I've been working my way through Trolltech's
>tutorial (and the API reference), and as far as I've seen they never use
>that form anywhere in their documentation.
>
>If that is the recommended form, why doesn't Trolltech use it?

Cross-posting to kde-core-devel to clarify the issue.

You are probably looking at Qt source code. Taking one file as an example 
(src/corelib/tools/qstring.cpp), we find:

#include "qstringlist.h"
#include "qregexp.h"
#include "qunicodetables_p.h"

But if you look into a header file (kernel/qvariant.h>, you'll see:
#include <QtCore/qmap.h>
#include <QtCore/qstring.h>

If you looks at http://docs.trolltech.com, you'll see that the recommended 
form for using QStringList is:

#include <QStringList>

Yet I've been telling people to use
#include <QtCore/QStringList>

Which form is correct?

Technically speaking, all of them are correct, provided you passed the 
correct -I options to your compiler, in your buildsystem. And Qt is 
compiled using qmake, which passes all the options to the compiler by 
default. In KDE code, using cmake, we will do that too.

However, I recommend that for header files, you only use the forms:
#include <QtModule/QClass>
or
#include <QtModule/qclass.h>

The reason for that is it requires less -I options to the compiler. If 
someone wants to write a quick Qt program, all he needs to set 
is -I$QTDIR/include and use that form. But that will only work as long as 
ALL headers that he includes do it in that form.

-- 
Thiago Macieira  -  thiago (AT) macieira.info - thiago (AT) kde.org
  thiago.macieira (AT) trolltech.com     Trolltech AS
    GPG: 0x6EF45358                   |  Sandakerveien 116,
    E067 918B B660 DBD1 105C          |  NO-0402
    966C 33F5 F005 6EF4 5358          |  Oslo, Norway
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 191 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20060328/504413a4/attachment.sig>
-------------- next part --------------
 
>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<


More information about the kde-core-devel mailing list