qobject基础的多重继承 [英] Multiple inheritance with qobject base

查看:724
本文介绍了qobject基础的多重继承的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

代码示例:

class TestOne : public QWidget // To fix this i need to modify  class QWidget : public virtual QObject{}; which belongs to qt
{
  // ...
};

class TestTwo : public virtual QObject
{
  // ...
};

class Test : public TestOne, public TestTwo
{
 // ...
};

有什么方法可以解决这个问题?

What are other ways to get around this problem?

推荐答案

QObject不是为多重继承而设计的。 QObject 不支持来自其他QObject的多重继承。如果从两个类继承,则只有第一个可以是QObject,第二个不是按照 http ://qt-project.org/doc/qt-4.8/moc.html

QObject is not designed for multiple inheritance. QObject doesn't support multiple inheritance from another QObjects. If you inherit from two Classes only the first one can be QObject and second not as per http://qt-project.org/doc/qt-4.8/moc.html


QObject的虚拟继承不是支持。

Virtual inheritance with QObject is not supported.

您可以在两个QObject之间建立关联并在它们之间转发信号。

You can make association between two QObjects and forward signals between them.

您可以以不需要信号/槽并且不从QObject继承的方式抽象您的常用功能。然后继承它。然后将MI中的QObject免费课程与您的班级混合。您可以通过Derived QObject

You can abstract your common functionalities in a way that doesn't require a signal/slot and don't inherit that from QObject. and then inherit from it. and then mix that QObject free class in MI with your your class. You can forward calls to those inherited methods through signals/slots from Derived QObject

这篇关于qobject基础的多重继承的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆