0

I created a QSqlTableModel, set a filter and used a QTableView to show a table of my filtered data. This works as expected...

model = new QSqlTableModel;
model->setTable("XXX");
model->select();

model->setFilter(filter);

table = new QTableView;
table->setModel(model);

However, when I try to compute the sum of all visible values of a column in the table view...

float sum = 0.0f;
for(int i=0;i<model->rowCount();i++)
    sum += model->record(i).value("amount").toFloat();

... I get the sum of ALL entries in the table model, NOT only of those items visible in the TableView (where the filter is applied).

How can I make my sum()-function to compute the sum of only those values which are visible in the TableView?

Thank you for your answers!

joe4
  • 1
  • 2

1 Answers1

0
model = new QSqlTableModel;
model->setTable("XXX");

model->setFilter(filter);

*model->select();//select after set filter*

table = new QTableView;
table->setModel(model);
currarpickt
  • 2,290
  • 4
  • 24
  • 39