You can use QSqlQueryModel::setQuery(). If your object is an QSqlQueryModel it will be read only so will need to implement several function to be able to edit the data in a view. I tried to implement what you wanted with QSqlTableModel * QSqlRelationalTableModel::relationModel ( int column ) and Relations set, but I just got segfaults. It is a const thing of some sort you may want to try to figure it out or subclass QSqlRelationalTableModel. But for a just reading the data a QSqlQueryModel should be sufficient. For some very complex behavior I have in the past sublcassed QAbstractTableModel and used a series of QSqlRelationalTableModels as the way I stored data.
Bookmarks