Originally Posted by
yuriry
After getting a related model you can obtain an index using QAbstractItemModel::index and data using QAbstractItemModel::data. I hope the row number is the same as in the original model.
Unfortunately no. QSqlRelationalTableModel::relationModel represents related table in database and it have number of rows equel to number of records in this table.
I think that this is not trivial problem because SELECT statement constructed in QSqlRelationalTableModel::selectStatement method remove all columns which are foreign keys to another tables.
In example.
Main table people with columns name, surname, town_id.
Related table towns with columns name, id.
After :
model.setTable("people");
QSqlRelationalTableModel model( parent, db);
model.setTable("people");
model.setRelation( 2,QSqlRelation("town", "id","name") );
To copy to clipboard, switch view to plain text mode
SELECT statement looks like :
SELECT "people"."name","people"."surname","relTblAl_3"."name" FROM "people","towns" "relTblAl_3" WHERE ("people"."town_id"="relTblAl_3"."id") ORDER BY "people"."name" ASC
SELECT "people"."name","people"."surname","relTblAl_3"."name" FROM "people","towns" "relTblAl_3" WHERE ("people"."town_id"="relTblAl_3"."id") ORDER BY "people"."name" ASC
To copy to clipboard, switch view to plain text mode
Bookmarks