In QSqlRelationalTableModel->setRelation(...), how can I specify a combination of fields to display?

  • Hi,

    I really like QSqlRelationalTableModel, but I want to specify a combination of fields (or a derived field) to display in a combobox instead of just one column values... How can I go about this?


  • Qt Champions 2017

    Not 100% sure what u ask to do. Sounds like u want to take data from model and hook to combobox.
    If that is correct. have a look at

    or do u mean like
    model->setRelation(2, QSqlRelation("city", "id", "name"));

  • It's more like the second option, using model->setRelation(...). the thing is, in QSqlRelation, we can choose to display only one column (in your example: "name") and what I need is the flexibility to display a computed column (without adding computed columns at the database)...

    Is this clear?

  • Lifetime Qt Champion


    Since it's only for display, you could use a QSqlQueryModel to populate the combo box with the computed values.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.