Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Solved QAbstractItemModel pure virtual function

    General and Desktop
    2
    3
    818
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • O
      ozzy last edited by

      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 1 Reply Last reply Reply Quote 0
      • Flotisable
        Flotisable @ozzy last edited by

        @ozzy
        read the document

        it says that QAbstractTableModel have provide default index() and parent()

        1 Reply Last reply Reply Quote 2
        • O
          ozzy last edited by

          @Flotisable
          You right,I'm so careless.

          1 Reply Last reply Reply Quote 0
          • First post
            Last post