Answer the question
In order to leave comments, you need to log in
How to get FK value in QSqlRelationalTableModel?
faced such a problem:
there are 2 tables:
Table1
ID(PK)
NAME
___
Table 2
ID(PK)
ID_TABLE1 I
establish a relationship with the first table
model->setRelation( 1, QSqlRelation( "Table1", "ID", "NAME" ) ) ;
model->select();
model->relationModel(1)->select();
and I need to get the FK from the model before submitting the db.
tried
model->setRelation( 1, QSqlRelation(" Table1", "ID", "NAME,ID_TABLE1 as ID_TABLE1 " ) );
but in that case the empty dropdown list
was an option to pull from the first table using
model->relationModel(1)->record(/*index?*/).value("ID").
but for this you need to know the row number in which the entry in the first table is located.
there is an assumption that you can get this number from the drop-down list of relation, but I don’t know how.
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question