Qt: bring base class method into slots in derived class
I have a class which derives from a QWid开发者_JS百科get 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.
精彩评论