Monday, December 12, 2011

QT_FORWARD_DECLARE_CLASS should be used for forward declaration of Qt classes

Using QT_FORWARD_DECLARE_CLASS, the forward declaration will still work if someone configures Qt with -qtnamespace:

For example, if someone configures a MyNamespace, QT_FORWARD_DECLARE_CLASS(QWidget) becomes:

namespace MyNamespace { class QWidget; }
using ::MyNamespace::QWidget;

whereas normal "class QWidget" forward declaration will cause a conflict since the class is declared outside the namespace.