0

I am working on a class that has two parent classes:

GetSetInterface which derives QObject and QSpinBox(which derives QObject aswell) And I Call it SpinBoxInterface

class GetSetInterface : public QObject
class SpinBoxInterface : public QSpinBox, public GetSetInterface

In the constructor of SpinBoxInterface I am trying to connect signal QSpinBox::valueChanged(int) to the signal GetSetInterface::sendInfo(int, QVariant), and here comes a problem:

When I write (of course in SpinBoxInterface class)

connect(this, QOverload<int>::of(&SpinBoxInterface::valueChanged), this, [=](int value){
        emit sendInfo(TYPE_ANYCHANGE, value);
    });

I Get an error non-static member 'connect' found in multiple base-class subobjects of type 'QObject',

However, when I write

GetSetInterface::connect(this, QOverload<int>::of(&SpinBoxInterface::valueChanged), this, [=](int value){
        emit sendInfo(TYPE_ANYCHANGE, value);
    });

I get an error ambigious conversion from derived class 'AxisSpinBox' to base class 'const QObject'. As long as I understand the first error ('connect found in multiple base-classes'), the second one feels weird, as GetSetInterface::connect has only one parent class, from where to get definition of connect - and it is only one QObject.

#define TYPE_ANYCHANGE 0 is used in a methods above

Lidbey
  • 251
  • 1
  • 12
  • 2
    You probably want virtual inheritance and have only one `QObject`. – Jarod42 Feb 08 '22 at 13:16
  • @Jarod42 I have tried to change `class GetSetInterface : public QObject` to `class GetSetInterface: virtual public QObject` and it didn't help – Lidbey Feb 08 '22 at 13:21
  • 2
    I wouldn't be surprised if multiple inheritance from `QObject` simply doesn't work. Are you sure you need to do it? Would encapsulation work instead? – Alan Birtles Feb 08 '22 at 13:40
  • I needed to do it because I am working on multiple QWidgets lists (ComboBox, LineEdit, SpinBox, DoubleSpinBox) and also I want to have a common type of interface for data in/out, so I can store it in QVector and just throw GetSetInterface::set and ::get on them. It seems to work with casting 'this' to 'QSpinBox*' in the SpinBoxInterface constructor(very weird for me, but works) – Lidbey Feb 08 '22 at 13:44
  • @JarMan I could probably use composition, the other case with making QObject in one base class 'private' doesn't seem to work. – Lidbey Feb 08 '22 at 13:48
  • I like the composition idea from this answer: [https://stackoverflow.com/a/68376543/487892](https://stackoverflow.com/a/68376543/487892) – drescherjm Feb 08 '22 at 13:54

0 Answers0