QAbstractItemModel pure virtual function
-
I learn Qt Mode/View from Qt example link text
QAbstractTableModel Inherits from QAbstractItemModel.
class MyModel : public QAbstractTableModel { Q_OBJECT public: explicit MyModel(QObject *parent = 0); int rowCount(const QModelIndex &parent) const; int columnCount(const QModelIndex &parent) const; QVariant data(const QModelIndex &index, int role) const; }
I just implements 3 pure virtual function of QAbstractTableModel .
But there are 5 pure virtual function in QAbstractItemModel:
int rowCount(const QModelIndex &parent) const; int columnCount(const QModelIndex &parent) const; QVariant data(const QModelIndex &index, int role) const; QModelIndex index (int row, int column, const QModelIndex & parent ) const; QModelIndex parent ( const QModelIndex & index ) const;
I read from book: You must implement all pure virtual funtions in base class so that you can create instance of subclass.
I don't implement all pure virtual funtions, why i can create MyModel instance ?
-
I learn Qt Mode/View from Qt example link text
QAbstractTableModel Inherits from QAbstractItemModel.
class MyModel : public QAbstractTableModel { Q_OBJECT public: explicit MyModel(QObject *parent = 0); int rowCount(const QModelIndex &parent) const; int columnCount(const QModelIndex &parent) const; QVariant data(const QModelIndex &index, int role) const; }
I just implements 3 pure virtual function of QAbstractTableModel .
But there are 5 pure virtual function in QAbstractItemModel:
int rowCount(const QModelIndex &parent) const; int columnCount(const QModelIndex &parent) const; QVariant data(const QModelIndex &index, int role) const; QModelIndex index (int row, int column, const QModelIndex & parent ) const; QModelIndex parent ( const QModelIndex & index ) const;
I read from book: You must implement all pure virtual funtions in base class so that you can create instance of subclass.
I don't implement all pure virtual funtions, why i can create MyModel instance ?
-
@Flotisable
You right,I'm so careless.