PDA

View Full Version : Weird behavior with QSqlRelationalTableModel & setFilter



Alir3z4
11th July 2011, 06:16
I have a weird problem with QSqlRelationalTableModel.
In Constructor my model&view initialize with this source:


// Create db model
model = new QSqlRelationalTableModel(ui->viewTableReport);
model->setTable("reports");

// Set headerData
model->setHeaderData(model->fieldIndex("customer_id"), Qt::Horizontal, tr("Name"));
model->setHeaderData(model->fieldIndex("tottal"), Qt::Horizontal, tr("Tottal"));
model->setHeaderData(model->fieldIndex("created"), Qt::Horizontal, tr("Created"));

// Set Relations to the other database tabels
model->setRelation(model->fieldIndex("customer_id"), QSqlRelation("customers", "id", "name"));

// Set edit strategy
model->setEditStrategy(QSqlRelationalTableModel::OnFieldC hange);

// Populate the model
/*
* Problem is here, on setFilter
*/
//model->setFilter("hidden=FALSE");
model->select();

// Set the model and hide the ID column
ui->viewTableReport->setModel(model);

// Customize data view
ui->viewTableReport->setColumnHidden(model->fieldIndex("id"), true);
ui->viewTableReport->setColumnHidden(model->fieldIndex("hidden"), true);

When i uncomment setFilter the QTableView shown nothing,it mean empty
Of course i have a lot record with "hidden=FALSE"
But weird section is here:

When i comment model->setRelation() everythings going be fine :0
I mean when i unset relations with other tables it's working pretty and those record with "hidden=FASE" clause just shown!
And i have couple of model, but those working sweet with relational, even with "customers" table.

Any idea for this situation?

Thank you!

*Update:

After posting this thread i found duplicate thread, i don't know it's i can solved with that solution.
It's my bad to posting duplicate.
but shoulda check is working or not.