staticMetaObject&qt_metacast等信号与槽之类的错误修复方法

If you’re trying to compile it you get an error:

tmp/moc/moc_Controller.cpp:45: error: 'staticMetaObject' is not a member of 'AbstractClass'
tmp/moc/moc_Controller.cpp: In member function 'virtual void* Controller::qt_metacast(const char*)':
tmp/moc/moc_Controller.cpp:61: error: 'qt_metacast' is not a member of 'AbstractClass'
tmp/moc/moc_Controller.cpp: In member function 'virtual int Controller::qt_metacall(QMetaObject::Call, int, void**)':
tmp/moc/moc_Controller.cpp:66: error: 'qt_metacall' is not a member of 'AbstractClass'
make: *** [tmp/objects/moc_Controller.o] Error 1

The error is caused by a bad order of inheritance.

Instead of this

class Controller :
	public AbstractClass, public QObject
{
   ...

you should use this

class Controller :
	public QObject, public AbstractClass
{
   ...

总结一下要自定义信号和槽的话首先你这个类要是一个QObject的子类, 如果需要多继承要将 QObject 放在前面, 同时, 还需要在类声明的开始使用 Q_OBJECT 宏

你可能感兴趣的:(qt,c++)