Multiple inheritance with qobject base

Code example:

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?

+6
source share
1 answer

QObject is not intended for multiple inheritance. QObject does not support multiple inheritance from other QObjects. If you inherit from two classes, then only the first can be a QObject, and the second not at http://qt-project.org/doc/qt-4.8/moc.html

Virtual inheritance with QObject is not supported.

You can establish a connection between two QObjects and direct signals between them.

You can abstract your common functions in such a way that you do not require a signal / slot and do not inherit it from QObject. and then inherit from it. and then add this QObject class to MI with your class. You can redirect calls to inherited methods via signals / slots from Derived QObject

+10
source

Source: https://habr.com/ru/post/923791/


All Articles