PDA

View Full Version : QSqlRelationalTableModel & QTableView



eaglo
16th December 2011, 20:21
hello folks,

i'm new to qt and currently trying to start with a little db app.

at the moment i'm using a QSqlRelationalTableModel and a QTableView in which i want to display the main table and its details of my app

the table layout is as follows
table contact:
* idContact
* customerId
* companyName
* countryId
* ...

table country:
* idCountry
* countryName
* countryCode
* telephonePrefix

my goal is to display
idContact customerId companyName countryCode countryName telephonePrefix
in the QTableView

... what is the best way to achieve this?

at the moment i'm setting relations in the QSqlRelationalTableModel, but with this i can only change countryId to countryName OR countryCode OR telephonePrefix - but i need to add all fields of country to the model (or to the view?)

insertColumn didn't help me ... it was possible to add the desired columns to the model, but i get weird select statements when i add the relation with the new index (sql WHERE gets confused and points to the wrong fields)

kind regards
michael