Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Filter the combobox options with QSqlRelationalTableModel
AneOrnic last edited by
I'm trying to make an editable table with QSqlRelationalTableModel.
The model is associated with a table that has a foreign key and a filter to display only those records associated with a given id. I programmed as follows:
model = new QSqlRelationalTableModel (this);
model-> setTable ("sessiongame_has_player");
model-> setFilter ("sessiongame_idsessiongame =" + idsessiongame);
model-> setRelation (1, QSqlRelation ("player", "nicknamePlayer", "nicknamePlayer"));
model-> select ();
ui.tablaView-> setModel (model);
When I run the program, the tableView table displays the combobox cell "nicknamePlayer" with all the options from the foreign table "player".
What I need is to filter these options. That is, I don't want to show all nicknames, but only nicknames that satisfy a certain condition. I tested with:
model-> setFilter ("relTblAl_1.Team_name_team = 'Female'");
But that doesn't work because what I do is filter the table model (sessiongame_has_player) and display only records in which the player belongs to the female team. I need to filter the combo box options. I would like to display only the nicknames of the female team.
Could anyone help me? Thank you very much!
Edit: please use @ tags around code sections; Andre