Using view/model/delegate in my application
-
wrote on 6 May 2015, 01:42 last edited by Robey Mardon 5 Jun 2015, 01:43
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
name
,model
,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 ♥ -
wrote on 6 May 2015, 04:18 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();
1/2