MOC Bug?
-
Hello,
I was asking myselfe if this is a bug:
namespace somenamespacename { #ifdef Q_OS_LINUX class myErrClass : public QObject { Q_OBJECT public: myClass(); signals: void mySignal(); } #endif class mySecClass : public QObject { Q_OBJECT public: mySecClass(); signals: void mySecSignal(); } }
Assuming i have implemented all functions in the cpp I get an error of undefined references for myErrClass. Looking in the moc file I saw that qmake did not created the moc-content for myErrClass.
If I remove the ifdef the content is created and everything is as expected.
-
Do you get the errors when Q_OS_LINUX is defined or not? Or do you get them always? Are the myErrClass functions also ifdeffed in the source file?
-
OK, I've checked now and although it is not mentioned in the official MOC documentation, this tool has trouble understanding any ifdefs.
See: "link":http://stackoverflow.com/questions/4246533/qt-signal-wrapped-in-an-ifdef and "link":http://grokbase.com/t/gg/android-qt/129q8e9fem/moc-doesnt-see-ifndef-android-guards.
-
I would put it more as "known issue" - but it's been there since the dawn of time and I don't remember anybody volunteering to fix it.
One of the problems I see is that MOC is run by qmake. But actual compilation flags are passed later - when the project is actually build. So implementing it properly in MOC is probably a big effort.
-
Hi,
IIRC, that's a limitation of Qt 4's moc, the Qt 5 version should work better in that aspect.
-
Just tested with your code as a base and the minor modifications it needed to build and got no error with Qt 5.4. Can you post a complete example that fails for you ?