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. A Question About Two QTableView Share One Model
Forum Updated to NodeBB v4.3 + New Features

A Question About Two QTableView Share One Model

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 2 Posters 62 Views 1 Watching
  • 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.
  • qazaq408Q Offline
    qazaq408Q Offline
    qazaq408
    wrote last edited by
    #1

    There is a Widget with two QTableView,and they own same data. For instance,viewA has "Name" and "Age",viewB also has "Name" and "Age", so i design a model like this

    class MyModel : public QAbstractTableModel{
    ..
    }
    

    Now in the Widget, i need the data will changed sync in two views, so plan A is that viewA and view B all own his model, and i synchronize data via by SIGNAL and SLOT,like

    MyModel* modelA = new MyModel();
    MyModel* modelB = new MyModel();
    viewA->setModel(modelA );
    viewB->setModel(modelB);
    
    connect(modelA, SIGNAL(set_data(int)), modelB, SLOT(change_data(int)));
    //and so on
    

    And plan B is that two view use one model, so i don't depand on SIGNAL and SLOT to change data, like this

    MyModel model_share = new MyModel();
    viewA->setModel(model_share);
    viewB->setModel(model_share);
    

    I programme a test project ,plan B can work,but i never use form like plan B and i maybe need use plan B in a large project.

    So,if i use PLAN B,it will bring some problem,or it's a normal way of desgin?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote last edited by
      #2

      Hi,

      Using multiple views on top of the same model is one of the core feature of the model view paradigm. You have one single source of data and present it through different (or similar) means to the user.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • qazaq408Q qazaq408 has marked this topic as solved

      • Login

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