Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QAbstractItemModel pure virtual function
Forum Update on Monday, May 27th 2025

QAbstractItemModel pure virtual function

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 1.2k Views
  • 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 Offline
    O Offline
    ozzy
    wrote on last edited by
    #1

    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 ?

    FlotisableF 1 Reply Last reply
    0
    • O ozzy

      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 ?

      FlotisableF Offline
      FlotisableF Offline
      Flotisable
      wrote on last edited by
      #2

      @ozzy
      read the document

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

      1 Reply Last reply
      2
      • O Offline
        O Offline
        ozzy
        wrote on last edited by
        #3

        @Flotisable
        You right,I'm so careless.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved