Old thread but I was looking for solution. Here is what You should do:
model->setRelation(model->fieldIndex("continent_id"), QSqlRelation("Table_2", "continent_id", "continent_name, continent_id as continent_id"));
or something like that. I have table Orders with contractor_id and Contractors with id so I had to use:
setRelation(this->fieldIndex("contractor_id"), QSqlRelation("Contractors", "id", "name, contractor_id as contractor_id"));
'displayColumn' in Qt documentation is misleading. It should be called displayColumns.




Reply With Quote
Bookmarks