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. Get related data from QSqlRelationalTableModel
Forum Updated to NodeBB v4.3 + New Features

Get related data from QSqlRelationalTableModel

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 1.4k 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.
  • Q Offline
    Q Offline
    qxoz
    wrote on last edited by
    #1

    Hi everyone!
    I have 2 related tables and model which bind them like this:
    @tbm_clientList->setRelation(3, QSqlRelation("mt_ctype", "id", "name"));@
    and issue is how to get "id" of related data on selected row?

    1 Reply Last reply
    0
    • Q Offline
      Q Offline
      qxoz
      wrote on last edited by
      #2

      I found some solution in qtcentre.org
      @class mymodel : public QSqlRelationalTableModel
      {
      Q_OBJECT
      public:
      virtual QVariant data(const QModelIndex &item, int role = Qt::DisplayRole) const;
      virtual QSqlRecord record(int row) const;
      };@

      @QSqlRecord mymodel::record(int row) const
      {
      QSqlTableModel mod;
      QSqlRecord rec = QSqlQueryModel::record(row);

      mod.setTable(tableName());
      mod.select();
      mod.setFilter(QString("idxxx = %2").arg(rec.value("idxxx").toInt()));
      
      return mod.record(0);
      

      }@

      but i think it's expensive solution

      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