C++ macro containing Q_OBJECT: moc error
-
I'm developping a c++/Qt program that will have several plugins.
For each class I have to define a plugin-interface that looks like this://my class class qwerty; //my interface class qwertyPlug : public QObject, myPlug { Q_OBJECT Q_INTERFACES(nPanPlug) Q_PLUGIN_METADATA(IID "org.myapp.plug") public: qwertyPlug() {qRegisterMetaType<qwerty *>("qwerty""*");} QByteArray name() {return "qwerty";} };
I created a macro (actually 2 since I'm not a c++ preprocessor guru):
#define MY_PLUGIN_BASE(__c_name,__appendix) \ class __c_name##__appendix : public QObject, myPlug { \ Q_OBJECT \ Q_INTERFACES(nPanPlug) \ Q_PLUGIN_METADATA(IID "org.myapp.plug") \ public: \ __c_name##__appendix() {qRegisterMetaType<__c_name *>(#__c_name"*");} \ QByteArray name() {return #__c_name;} \ }; #define MY_PLUGIN(__c_name) MY_PLUGIN_BASE(__c_name,Plug)
so that In my code (where
qwerty
is defined) I just have to add:MY_PLUGIN(qwerty)
which will expand (output of
g++ -E
):class qwertyPlug : public QObject, myPlug { Q_OBJECT Q_INTERFACES(nPanPlug) Q_PLUGIN_METADATA(IID "org.myapp.plug") public: qwertyPlug() {qRegisterMetaType<qwerty *>("qwerty""*");} QByteArray name() {return "qwerty";} };
and it looks ok (sorry for the readability but I dont know how to add newlines..) and works if copy/paste the above line in my code but...
When I compile my project I get errors from the
moc
:Error: Class declaration lacks Q_OBJECT macro.
Do anyone have an idea?
p.s. here is my SO question
http://stackoverflow.com/questions/41056941/c-macro-containing-q-object -
@bibi
are you using Qt4? -