[Qt-interest] When is QT_FORWARD_DECLARE_CLASS to be used?

Thiago Macieira thiago.macieira at trolltech.com
Sat Apr 18 09:03:30 CEST 2009


Scott Aron Bloom wrote:
>In the code... Its defined as the following
>#ifndef QT_NAMESPACE
># define QT_FORWARD_DECLARE_CLASS(name) class name;
>#else
># define QT_FORWARD_DECLARE_CLASS(name) \
>    QT_BEGIN_NAMESPACE class name; QT_END_NAMESPACE \
>    using QT_PREPEND_NAMESPACE(name);
>#endif
>
>So they qt developers created a shortcut for forward declaring a class
>that would take care of the namespace optionally being there...
>
>Honestly.. Ive never used the macro... but I don't think it would hurt,
>especially if you plan on using the namespace...
>
>BTW. its in qglobal.h

The namespace feature was added because many users requested it. But, by 
definition, it's a source- and binary-incompatible change and it's never 
enabled by default, nor will we ever use it in the binary packages we 
release. It's there if you want to use it when you build Qt.

That means your application doesn't have to handle namespaces. That is, 
you can choose to never use the QT_FORWARD_DECLARE_CLASS macro.

Qt examples and demos have to use it. But user applications don't. In 
fact, user applications should "know" which namespace Qt was compiled with 
(if any at all) and hardcode it.
-- 
Thiago Macieira - thiago.macieira (AT) nokia.com
  Senior Product Manager - Nokia, Qt Software
      Sandakerveien 116, NO-0402 Oslo, Norway
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090418/e9492af6/attachment.bin 


More information about the Qt-interest-old mailing list