I a project of mine, written in Qt, I have a QWidget Widget
that should display either a MyTreeWidget
(inheriting from QTreeWidget
) or a MyTableWidget
(inheriting from QTableWidget
)
Constraints
Widget
shouldn't know who it is talking to. Therefore it must (??) own a class inherited by theMy(Tree|Table)Widget
MyTreeWidget
andMyTableWidget
share a lot of code and I don't want to copy paste this code. So I thought of making them inherit from aMyGenericView
which inherit fromQAbstractItemView
The Interfaces
#include <QAbstractItemView>
#include <QTreeWidget>
#include <QTableWidget>
class MyGenericView : public QAbstractItemView
{
Q_OBJECT
public:
MyGenericView();
};
class MyTreeWidget : virtual public QTreeWidget,
virtual public MyGenericView
{
Q_OBJECT
public:
explicit MyTreeWidget(QWidget *parent = 0);
};
class MyTableWidget : public MyGenericView, public QTableWidget { ... };
class Widget : public QWidget
{
Q_OBJECT
public:
explicit Widget(QWidget *parent = 0) :
QWidget(parent)
{
m_genericView = new MyTreeWidget();
}
private:
MyGenericView *m_genericView;
};
The Error
erreur : invalid new-expression of abstract class type 'MyTableWidget'
m_genericView = new MyTableWidget();
note: because the following virtual functions are pure within 'MyTableWidget':
class MyTableWidget : public QTableWidget, public MyGenericView
And the same for MyTreeWidget.
So how would you correct this?