[Qt-interest] qmake and scope: prevent moc from moc'ing file?

Oliver.Knoll at comit.ch Oliver.Knoll at comit.ch
Thu Feb 10 15:13:39 CET 2011


Hi,

I hit a rather esoteric problem: it seems that when running qmake it does not prevent moc from running on files which are in a different scope. That is on Qt 4.7.1 (MinGW binary build).

This is my scenario: I have an interface Foo.h, which is implemented by platform-specific code, as in Foo_Windows, Foo_Mac etc. The source and header files are naturally placed in qmake scopes, as in:

if (macx) {
    HEADERS += Foo_Mac.h
    SOURCES += Foo_Mac.cpp
} else:win32 {
    HEADERS += Foo_Windows.h
    SOURCES += Foo_Windows.cpp
} etc.

This compiles and links all fine, as expected.

Now for the Mac implementation - and currently only for the Mac - I wanted to also subclass from QObject, so I did:

// Foo_Mac.h
class Foo : public QObject, public Foo
{
    Q_OBJECT // workaround: remove this (if possible)
public:
    ....
};

Now it turns out that when compiling the code on e.g. Windows I get linker errors, because the moc also produces code from this Foo_Mac.h (even though that header is put in a different scope).

Off course in my case I get away by removing the Q_OBJECT macro from Foo_Mac.h. This is possible since all I want to do is to install this class as an event filter on another QObject - so I don't need meta class information, nor signals/slots. I could also make the interface class Foo.h inherit from QObject instead, and add the Q_OBJECT macro there, if needed. But also then I would probably hit the same problem again, should I want to add the Q_OBJECT macro also to it's implementing classes (because I would need the meta class information there as well, for instance).

So it seems that qmake does not take the scopes into account when generating the moc steps which looks like a qmake bug to me? Or at least an "unsupported feature"? Google did not turn up with anything useful. Or am I doing something wrong?


Thanks,
  Oliver
-- 
Oliver Knoll
Dipl. Informatik-Ing. ETH
COMIT AG - ++41 79 520 95 22





More information about the Qt-interest-old mailing list