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. In QSqlRelationalTableModel->setRelation(...), how can I specify a combination of fields to display?
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 754 Views 2 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.
  • J Offline
    J Offline
    jdent
    wrote on 29 Feb 2016, 20:55 last edited by
    #1

    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?

    Thanks
    Juan

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 29 Feb 2016, 21:07 last edited by mrjj
      #2

      Hi
      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
      http://doc.qt.io/qt-5.5/qdatawidgetmapper.html#details

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

      1 Reply Last reply
      0
      • J Offline
        J Offline
        jdent
        wrote on 29 Feb 2016, 22:51 last edited by
        #3

        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?

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 29 Feb 2016, 23:30 last edited by
          #4

          Hi,

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

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          1

          1/4

          29 Feb 2016, 20:55

          • Login

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