Hi,
I have this model:
void CidadaoDialog::construirModeloCidadao()
{
modeloCidadao->setTable("Cidadao");
modeloCidadao
->setRelation
(cidadao_localidade,
QSqlRelation("Localidade",
"idLocalidade",
"nome"));
modeloCidadao->setHeaderData(cidadao_idCidadao, Qt::Horizontal, tr("B.I."));
modeloCidadao->setHeaderData(cidadao_nome, Qt::Horizontal, trUtf8("Nome"));
modeloCidadao->setHeaderData(cidadao_localidade, Qt::Horizontal, trUtf8("Localidade"));
modeloCidadao->setSort(cidadao_nome, Qt::AscendingOrder);
modeloCidadao->select();
}
void CidadaoDialog::construirModeloCidadao()
{
modeloCidadao->setTable("Cidadao");
modeloCidadao->setRelation(cidadao_localidade, QSqlRelation("Localidade", "idLocalidade", "nome"));
modeloCidadao->setHeaderData(cidadao_idCidadao, Qt::Horizontal, tr("B.I."));
modeloCidadao->setHeaderData(cidadao_nome, Qt::Horizontal, trUtf8("Nome"));
modeloCidadao->setHeaderData(cidadao_localidade, Qt::Horizontal, trUtf8("Localidade"));
modeloCidadao->setEditStrategy(QSqlRelationalTableModel::OnRowChange);
modeloCidadao->setSort(cidadao_nome, Qt::AscendingOrder);
modeloCidadao->select();
}
To copy to clipboard, switch view to plain text mode
Used by this view:
void CidadaoDialog::construirVistaCidadao()
{
vistaCidadao = ui->tableView;
vistaCidadao->setModel(modeloCidadao);
vistaCidadao->setFixedWidth(605);
vistaCidadao->verticalHeader()->hide();
vistaCidadao->setColumnWidth(cidadao_idCidadao, 100);
vistaCidadao->setColumnWidth(cidadao_nome, 300);
vistaCidadao->setColumnWidth(cidadao_localidade, 200);
}
void CidadaoDialog::construirVistaCidadao()
{
vistaCidadao = ui->tableView;
vistaCidadao->setModel(modeloCidadao);
vistaCidadao->setItemDelegate(new QSqlRelationalDelegate(vistaCidadao));
vistaCidadao->setSelectionMode(QAbstractItemView::SingleSelection);
vistaCidadao->setSelectionBehavior(QAbstractItemView::SelectRows);
vistaCidadao->setFixedWidth(605);
vistaCidadao->verticalHeader()->hide();
vistaCidadao->setColumnWidth(cidadao_idCidadao, 100);
vistaCidadao->setColumnWidth(cidadao_nome, 300);
vistaCidadao->setColumnWidth(cidadao_localidade, 200);
}
To copy to clipboard, switch view to plain text mode
If i set a filter like this ...
void CidadaoDialog::filtrar_nome()
{
filtro = "nome like '%"+ui->filtroNome->text()+"%'";
modeloCidadao->setFilter(filtro);
modeloCidadao->select();
}
void CidadaoDialog::filtrar_nome()
{
QString filtro;
filtro = "nome like '%"+ui->filtroNome->text()+"%'";
modeloCidadao->setFilter(filtro);
modeloCidadao->select();
}
To copy to clipboard, switch view to plain text mode
... i get no records displyed on the view.
If i comment line 4 on the model code it works as expected, displaying all record tha match the texte entered on ui->filtroNome (lineEdit Widget).
What am i missing here?
Thanks
Bookmarks