Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Using view/model/delegate in my application

    General and Desktop
    2
    2
    566
    Loading More Posts
    • 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.
    • Robey Mardon
      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 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 Reply Quote 0
      • A
        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();
        
        1 Reply Last reply Reply Quote 1
        • First post
          Last post