A Question About Two QTableView Share One Model
-
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?
-
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.
-
Q qazaq408 has marked this topic as solved