Suppose I want to implement a model/view architecture using the QTableView
and QAbstractTableModel
classes. So I subclass the QAbstractTableModel
to create class MyModel
and implement the QAbstractTableModel
interface. Then connect the instance of this model to a QTableView
instance using the setModel
method.
#include <QtGui/QApplication>
#include <QtGui/QTableView>
#include "mymodel.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QTableView tableView;
MyModel myModel(0);
tableView.setModel( &myModel );
tableView.show();
return a.exec();
}
But how can I make the model read only? I cannot declare
const MyModel myModel(0);
because setModel takes a non constant argument. I reimplemented only constant methods of QAbstractTableModel.