Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Two or more model on the same modelview



  • Let’s say I have a table for customer and other one for address and the address table has some fields like ‘zip_code’, ‘city’,‘state’ and so on and the customer table has a field called 'addresd_id' which is a foreign key for the table address (the id field). What should I do if I want to show a TableView with the complete information about customers (including the all address table fields)? The QSqlRelationalTableModel just allow me to link a foreign key to ONE field on other table but in fact I want to link one foreign key to the complete row in other table and show all fields of that table. Does someone have a solution?



  • Unless you need editing QSqlQueryModel. If you need editing you will have to sub-class it as the relational model does not suit your needs.



  • Just an idee: If case you can extend the database, create a view in the database from both address table and customer table. And than use this view in the model.


Log in to reply