Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Filter the combobox options with QSqlRelationalTableModel
Qt 6.11 is out! See what's new in the release blog

Filter the combobox options with QSqlRelationalTableModel

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 1.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    Hi all,

    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

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved