0

I have a QSqlRelationalTableModel like this:

rel_model = QSqlRelationalTableModel(self, connectDB)
rel_model.setTable("main_table")
rel_model.setRelation(1, QSqlRelation("linked_table", "id", "name"))
rel_model.select()

But now the data in the linked_table changed (e.g. a row is added). How can I update the relation to use the modified data of the linked_table.

Note: I don't want to use rel_model.select(), because some data in the main_table were modified too, and they would be discarded then. I am using a SQlite-Database.

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
vezzon
  • 177
  • 1
  • 11
  • What disadvantage have the usage of a QSqlRelationalTableModel this way?. I am new in programming and on using this forum, so how can i contact you directly? – vezzon Mar 27 '20 at 16:46
  • Isn't it possible to post the answer/hint in this forum? (Or to add a file with the code?) – vezzon Mar 27 '20 at 17:08
  • I did post a hint to the answer -- that being look into MVC Methodology which basically states the View (Gui) is completely divorced from the Model (Data Source aka Database) such that the View does not know what its data source is nor does it care and the Model does not know or care what is being done with the data it is providing. As the 2 pieces talk to the Controller (aka Data Router) and it handles all the direct communications via API calls to and from the View and Model. Does that help any? – Dennis Jensen Mar 27 '20 at 17:16
  • As for the python class database template no I cannot drop it into a comment nor can I post an external source to it in a question I did not post. I might have shared it previously some where on this forum but I cannot say for sure on that. – Dennis Jensen Mar 27 '20 at 17:18
  • I think, i have understood the concept of MVC. But a small and simple example to implement this, would be very helpfull. E.g. to use data-relations in my application as long as you recommended not to use QSqlRelationalTableModel. I will search in the internet, and this is my contact for a hint: franz (dot) fisch (at) aon (dot) at – vezzon Mar 27 '20 at 17:46
  • Okay sent you a test email – Dennis Jensen Mar 27 '20 at 18:34

1 Answers1

0

Maybe you can look our open Qt project: github

This project contains a wrapper above QSqlTableModel + QTableView and realize PblTableDlg class with basic table functionaliy. We used a new variant of QSqlRelationalTableModel = PblSqlRelationalTableModel.