View Full Version : Weird behavior with QSqlRelationalTableModel & setFilter

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);

// 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

// Set the model and hide the ID column

// 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!


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.