Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Using view/model/delegate in my application

Using view/model/delegate in my application

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 692 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Robey Mardon
    wrote on 6 May 2015, 01:42 last edited by Robey Mardon 5 Jun 2015, 01:43
    #1

    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 ♥

    1 Reply Last reply
    0
    • A Offline
      A Offline
      alex_malyu
      wrote on 6 May 2015, 04:18 last edited by
      #2

      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 Reply Last reply
      1

      1/2

      6 May 2015, 01:42

      • Login

      • Login or register to search.
      1 out of 2
      • First post
        1/2
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved