PDA

View Full Version : QSqlRelationalTableModel: get non-resolved value of item



ak
13th April 2008, 00:03
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?

wysota
13th April 2008, 10:37
Did you try Qt::EditRole? It probably returns the foreign key and not the related value.

ak
14th April 2008, 21:56
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 :)

ak
14th April 2008, 22:50
QSqlRelationalTableModel doesn't work with MySQL views at all...
So, I need two models for this table: one with relations set and other without..

wysota
14th April 2008, 23:03
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.

ak
15th April 2008, 07:08
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...

wysota
15th April 2008, 08:03
QSqlRelationalTableModel overrides completely all foreign keys with their values and i get record with values already resolved...
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?


Qt coding is not so fun in this place...

Hmm... You ask Qt for a car and you are complaining it gave you a car instead of a bicycle?

ak
17th April 2008, 22:17
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?

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.
Or don't i just know what i realy need? :confused:

wysota
17th April 2008, 22:38
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.