1
votes

I have a class which derives from a QWidget and a model class. Based on my reading, I can't have the model class to derive from QObject.

class PageWidget : public QWidget,
        public MyModelClass
{
...
};

the model class MyModelClass already have method to set properties such as setWidth(bool). It seems that I can't use those method directly as slots. If I declare:

QObject::connect(button, SIGNAl(dataChanged(bool)), this, SLOT(setWidth(bool)));

Qt complains at runtime that no slot setWidth(bool). I have to manually add each method into PageWidget, which simply calls the same method of MyModelClass.

Is there any way to bring base methods into slots without redeclaring every method?

1
Yes: don't use multiple inheritance :-) Are you certain you need it? Especially if you have method name conflicts, you're setting yourself up for a lot of pain. - Mat

1 Answers

5
votes

QMetaObject (the Qt part that allow you to use slots) and multiple inheritance do not mix. You solution of creating "pass through" slots is a way of solving it. However, if you do not need to do the multiple inheritance, I wouldn't do it. Just from the look of things, it seems weird for a PageWidget to derive from both a Widget and a Model. It probably makes more sense to have it contain the model instead.