List data from two tables in the tableView

Asked

Viewed 148 times

1

What do I do to list two table data on tableView?

Sqlite Database(Example):

tb_venda
  tb_produto
  tb_valor
  tb_cliente_id (Id do cliente "tb_cliente")

tb_cliente
  tb_cliente_id (id primary key)
  tb_nome  
  tb_estado

With QSqlRelationalTableModel I can only carry the client’s name. I also need the state.

relacao = new QSqlRelationalTableModel(this); 
relacao->setTable("tb_venda");
relacao->setRelation(2, QSqlRelation("tb_cliente", "tb_cliente_id", "tb_nome"));
relacao->select();
ui->tableView->setModel(relacao);

1 answer

0


Solved: The QSqlRelationTableModel It has only one column. To solve the problem, I had to use the QSqlQueryModel with LEFT JOIN.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.