December 29, 2010

syrianzoro syrianzoro
Lab Rat
63 posts

multipleModels/oneView

Page  
1

Qt has provided a Quick way to display data in a grid or tree using model/view architecture, but they assumed that one view can display one model using one datasource like SQL table, I need away to display multiple Models at the same time in one tableView .

the problem come from the need of doing many DML operations visually by the end user.

 Signature 

Qt is the future

18 replies

December 29, 2010

CreMindES CreMindES
Lab Rat
211 posts

Could you be more specific about your problem?

BTW you could maybe unite your data before viewing it, or making up your model…

December 29, 2010

syrianzoro syrianzoro
Lab Rat
63 posts

  1.     QSqlTableModel *model = new QSqlTableModel();
  2.        model->setTable("person");
  3.  
  4.     QTableView *view = new QTableView;
  5.     view->setModel(model);

what if I need to insert data like this :
person: name,lastname,job,;
contactInfo: personId,means,type

the above data have to be in the same view.

 Signature 

Qt is the future

December 29, 2010

VCsala VCsala
Lab Rat
339 posts

What about the QSqlRelationalTableModel? I think for this kind of relation you can use that model.

December 29, 2010

Gerolf Gerolf
Hobby Entomologist
3287 posts

In general, you have proxy modles where you can combine data from different sources, you could create your own model that collects data from different souces…

As it seams, you want to use SQL models, I would try using a proxy model on top of the original ones to combine the data.

 Signature 

Nokia Certified Qt Specialist.
Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

December 29, 2010

syrianzoro syrianzoro
Lab Rat
63 posts

Ok Vcsala, but this is the maximum number of tables you can use at the same time ,you can use two tables.

it is common to display all cells as one row from different tables to be updated by the user at the same time.

 Signature 

Qt is the future

December 29, 2010

CreMindES CreMindES
Lab Rat
211 posts

Yes, Gerof is right.

(but you can set more colums and so on in an QSqlTableModel)

December 29, 2010

Denis Kormalev Denis Kormalev
Lab Rat
1654 posts

syrianzoro, I think that custom model will be the solution for your problem. It will take some efforts to make it, but it will cover all your neads.

December 29, 2010

syrianzoro syrianzoro
Lab Rat
63 posts

Denis Kormalev, I think you are right, but I try to check if any one have other way , that will be annoying to make ModelList :) , and I will be obliged to make a custom QTableView .

 Signature 

Qt is the future

December 29, 2010

Gerolf Gerolf
Hobby Entomologist
3287 posts

You shall not create a view, you shall create a model. And creating models is not so dificult, I did that many times now.

You just have to decide, whether you create your own model or a proxy model. If you don’t need the single base models stand alone, creating one model is easier than creating a proxy model.

More about creating xutsom model can be found here [doc.qt.nokia.com]

Afaik there are no model inside Qt where you can combine different sources into one model. Perhaps there is some thirt party solution, but that I don’t know.

 Signature 

Nokia Certified Qt Specialist.
Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

December 29, 2010

ixSci ixSci
Lab Rat
206 posts

and I will be obliged to make a custom QTableView

Why? If you have custom model it doesn’t force you to create your own view as long as your model inherits QAbstractItemModel.

December 29, 2010

Volker Volker
Ant Farmer
5428 posts

It does not make any sense that a (Table)View works on more than one model. From both a programmers and a users view this is not intuitive and error prone.

As Gerolf already suggested, it’s the best to make either your own ItemViewModel or try to combine the existing ones (you can add more than one table to QSqlRelationalTableModel).

December 29, 2010

fcrochik fcrochik
Lab Rat
517 posts

It seems that you are gathering data from a database. If that is the case and you just need a read-only view you can just combine the data sources (tables) on your sql statement and use a QSqlQueryModel

 Signature 

Certified Specialist & Qt Ambassador Maemo, Meego, Symbian, Playbook, RaspberryPi, Desktop… Qt everywhere!

December 29, 2010

VCsala VCsala
Lab Rat
339 posts
syrianzoro wrote:
but this is the maximum number of tables you can use at the same time ,you can use two tables.

Actually it is not true, the number of the tables is not limited. You have a master table which has several foreign keys to other tables and you can set all the relations to those tables. If you want to do a read/write model it is recommended to use the QSqlRelationalDelegate.

June 24, 2013

nasit.bhavin nasit.bhavin
Lab Rat
12 posts

I have same question. I have tableview and I want to display multiple tables from MYSQL on same view at a time. Is there any solution exist without creating custom model/view??

July 6, 2013

nasit.bhavin nasit.bhavin
Lab Rat
12 posts

No Solutions..!!!

Page  
1

  ‹‹ Question about Vista/7 volume controller.      [Moved] Connecting signal and slot of different affinity ››

You must log in to post a reply. Not a member yet? Register here!