2

I want to create a inheritance system in one of my Qt applications where there is a QObject derived class "Abstract1" that implements two signals and its derived classes, most of which will be QWidget derived.

The problem is that, the way I'm doing, is leading to "error: 'QObject' is an ambiguous base of " errors. A research on SO revealed the reason for that: I'm including two instance of QObject, one coming from my "Abstract1" class and the other from "QWidget":

class MyNewClass : public Abstract1, public QWidget

My question: how can I avoid the problem but still maintain the structure I want? That is, pure QObject class with the signals and subclasses which include this one and are also QWidget derived?

Momergil
  • 2,213
  • 5
  • 29
  • 59
  • 3
    Maybe derive `Abstract1` from `QWidget` and `MyNewClass` from `Abstract1` class only? – vahancho Dec 08 '14 at 12:39
  • 2
    Will you need to use `Abstract1` polymorphically (that is to say, do you work with `Abstract1&` or `Abstract1*`), or is this just about not having the signal code in a hundred places? – Wintermute Dec 08 '14 at 12:59
  • 2
    Bad news: http://stackoverflow.com/questions/8578657/qobject-multiple-inheritance – kiss-o-matic Dec 08 '14 at 14:23
  • You can't inherit two `QObject`s! it is forbidden. Most probably you can solve by "having" (filed) not by "being" (not inheritance). http://stackoverflow.com/questions/49002/prefer-composition-over-inheritance – Marek R Dec 08 '14 at 14:31
  • @kiss-o-matic there are simple workaround, if you need to support both: qt sig/slot and interfaces: http://stackoverflow.com/questions/17943496/declare-abstract-signal-in-interface-class/17943699#17943699 – Dmitry Sazonov Dec 08 '14 at 15:40

0 Answers0