QSqlTableModel - filter not working?



  • Hi!

    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!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.