• 4958阅读
  • 0回复

转自CoCo:Multiple inheritance and Q_OBJECT [复制链接]

上一主题 下一主题
离线ynshisss
 

只看楼主 倒序阅读 楼主  发表于: 2008-08-19
— 本帖被 XChinux 执行加亮操作(2008-08-19) —
转自http://coffeeandcode.blogspot.com/2008/01/multiple-inheritance-and-qobject.html

I found out today, while working on porting a Motif application to Qt, that when you are inheriting from more than one class and not all of them are derived from QObject, you should make sure the first one does inherit QObject if you want to use the Q_OBJECT macro. For instance:


class A : public QObject {};
class B {};


class C : public A, public B
{
Q_OBJECT

};


If you do it the other way, (class C : public B, public A) you will get errors inside the moc_C.cxx file saying that it couldn't find the QMetaObject members of class B (which it doesn't have) because moc only looks at the first base class listed.
There all sorts of other little things like this which you can read about in the Qt moc documentation (for instance, nested classes cannot have signals or slots).
快速回复
限100 字节
 
上一个 下一个