Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QSqlTableModel - filter not working?
Qt 6.11 is out! See what's new in the release blog

QSqlTableModel - filter not working?

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 543 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    joe4
    wrote on last edited by
    #1

    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!

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved