Important: Please read the Qt Code of Conduct -

Does QTableView call only on QAbstractTableModel's virtual functions when it needs to display data?

  • In "2.4 Setting up Headers for Columns and Rows" in the Qt5.7 Model View tutorial, the file "mymodel.cpp" has 4 virtual functions for the class MyModel: QAbstractTableModel : rowCount, columnCount, data, and headerData. I'm noticing that all these functions return data that is displayed by the QTableView view. Does that mean Qt views (like QTableView) communicate with Qt models by using virtual functions from the Qt models (like models of QAbstractItemModel and QAbstractTableModel)? I'm pretty sure that's how models and views work, I just want to make sure I'm getting it right.

  • Lifetime Qt Champion


    Not all methods are virtual. QAbstractItemModel provides the foundation to build your own custom models and you'll have to re-implement parts of the virtual methods in order to make it work the way you want it.

  • That helps clear some confusion, thanks.

  • To clarify, that is an interface i.e. if you implement a View you should only rely on methods and signals defined in QAbstractItemModel so your view will work with all models implementing that interface correctly. QAbstractItemModel is the bridge between model and view (and delegate)

Log in to reply