QSqlRelationalTableModel::data( const QModelIndex & index, int role = Qt::DisplayRole ) returns display values for items from relation columns, but is there a way to get the index value for them, as it was in the original table before resolving?
QSqlRelationalTableModel::data( const QModelIndex & index, int role = Qt::DisplayRole ) returns display values for items from relation columns, but is there a way to get the index value for them, as it was in the original table before resolving?
Did you try Qt::EditRole? It probably returns the foreign key and not the related value.
Yes, it would be natural if Qt::EditRole did so, but unfortunatly it doesn't (it would be cool to have something like Qt::ForeignKeyRole for QSqlRelationalTableModel).
The only way i found is to create view with duplicated column in my database and resolve one of two![]()
QSqlRelationalTableModel doesn't work with MySQL views at all...
So, I need two models for this table: one with relations set and other without..
Naaa... it's not that bad. You can always use QSqlQueryModel::record() which will return the real record, with the foreign key instead of resolved relation.
QSqlRelationalTableModel overrides completely all foreign keys with their values and i get record with values already resolved... Qt coding is not so fun in this place...
So use the relation model and check the index yourself. What do you need it for anyway? What's the point in hiding foreign keys if you want to access them later on?
Hmm... You ask Qt for a car and you are complaining it gave you a car instead of a bicycle?Qt coding is not so fun in this place...
QSqlRelationalTableModel is very helpful when i want to show one table, but if i want to fill the dialog with additional info about some of fereign keys (e. g. mesure unit and producer of requested product from one of requests), i need non-resolved index, other words, i need functionality of both car and bicycle.What do you need it for anyway? What's the point in hiding foreign keys if you want to access them later on?
Hmm... You ask Qt for a car and you are complaining it gave you a car instead of a bicycle?
Or don't i just know what i realy need?![]()
I don't understand what you mean by "additional info about some of foreign keys". A key is a key (number), nothing more. If you want more information retrieved from the other table either use a view (in terms of the database, not model-view), use QSqlQueryModel, use a proxy model or use the base implementation of data - explicitely call QSqlTableModel::data instead of QSqlRelationalTableModel::data.
Bookmarks