[Qt-interest] problems with moc: Warning: No relevant classes found. No output generated.

Colin S. Miller no-spam-thank-you at csmiller.demon.co.uk
Tue Apr 20 00:06:15 CEST 2010


G. Allegri wrote:
> Ops, sorry, it works now.
> But I have another related question: if I have a file which includes 
> headers with QObjects declarations, should it be "moced"? In other 
> words, is a not-moced translation unit able to link to a QObjects lib 
> (referred into its header files)?
> 
Giovanni,

You don't have to.
MOC doesn't expand the #include lines.

Outside of MOC, Q_OBJECT expands to the declaration of
several member functions.

When MOC processes a file, it scans for Q_OBJECT.
It then provides the definition for these functions, assuming
that the first base class of the current class is derived from QObject.

If you do want to expand the #include lines, then
surround them with
// MOC_SKIP_BEGIN
and
// MOC_SKIP_END

This stops MOC from processing the included files.
Failure to prevent this will lead to double-definition
of the MOC functions, and obscure link errors.


It can be instructive to look at the MOC generated .cpp
file, to get an idea of what goes on under the hood.

HTH,
Colin S. Miller






More information about the Qt-interest-old mailing list