Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Using view/model/delegate in my application
Robey Mardon last edited by Robey Mardon
I read the entire Model/View Programming Documentation but I still don't get it, I really need an explanation of a real life application.
I need to create an application for cars, I need to create a table with the columns
brand, and so on... and of course the rows would be the data, that data is within a database, probably SQLite. I want to insert more cars on that model and at the same time update on the view, and the user can delete a car from the table and delete from the database... how can I do this using the MVC/D approach? Thanks ♥
alex_malyu last edited by
You will create a model which had to return data from database ( for example name for column 1 , model for column 2 and so on ).
Mostly likely you would want to use one of the existing SQL Model Classes connecting it to QSqlDatabase.
For example QSqlTableModel .
QSqlTableModel *model = new QSqlTableModel(parentObject, database); model->setTable("employee"); model->setEditStrategy(QSqlTableModel::OnManualSubmit); model->select(); model->setHeaderData(0, Qt::Horizontal, tr("Name")); model->setHeaderData(1, Qt::Horizontal, tr("Salary")); QTableView *view = new QTableView; view->setModel(model); view->hideColumn(0); // don't show the ID view->show();