Important: Please read the Qt Code of Conduct -

Using view/model/delegate in my application

  • 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 ♥

  • 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->setHeaderData(0, Qt::Horizontal, tr("Name"));
     model->setHeaderData(1, Qt::Horizontal, tr("Salary"));
     QTableView *view = new QTableView;
     view->hideColumn(0); // don't show the ID

Log in to reply