문제

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?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top