Hi,
My problem is: SqlRecord get by record() function from QSqlRelationalTableModel always (?) returns related value for column with foreign key - not original key value. Is there any method to obtain key value from record?
For instance:
Table 1:
country_id country_name continent_id
1 France 1
2 Germany 1
3 USA 2
Table 2:
continent_id continent_name
1 Europe
2 North America
We construct QSqlRelationalTableModel where continent_id in Table_1 is replaced by continent_name from Table_2:
QSqlRelationalTableModel *model = new QSqlRelationalTableModel;
model->setTable("Table_1");
model->setRelation(model->fieldIndex("continent_id"), QSqlRelation("Table_2", "continent_id", "continent_name"));
Than when we want to read data (first row i.e.) from model we use QSqlRecord:
....
QSqlRecord record = model->record(0);
Than - if we want to get continent_id field (using value function):
QString continent_id = record.value("continent_id").toString();
we will get empty string. Only continent_name is available.
My goal is to get continent_id, and I don't know how to do it.
If you put record to qDebug() You will see that record doesn't contain continent_id field.
Any suggestions welcome
kawoN
Bookmarks