Qt - How do I add a calculated column to a QsqlRelationalTableModel?

I have a table view displayed

part description, quantity, price

And I have a model / view using this code

model = new QSqlRelationalTableModel(this);
model->setTable("parts");
model->setRelation(3,QSqlRelation("part_tbl","part_id","part_desc"));

model->select();
ui->tableView->setModel(model);

      

I need to add a new column that shows the price of a quantity * in a table view. It is important to know that I am using QsqlRelationalTableModel

Help rate, thanks in advance

+2


source to share


1 answer


I believe your best way to handle this is to make either a model that inherits QSqlRelationalTableModel or one that acts as a proxy (and contains an element for the model). Your new model will add an extra column, and when data is requested for that column, use the data from the other columns to figure out what is required.



+2


source







All Articles