Get related data from QSqlRelationalTableModel

  • 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?

  • I found some solution in
    @class mymodel : public QSqlRelationalTableModel
    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.setFilter(QString("idxxx = %2").arg(rec.value("idxxx").toInt()));
    return mod.record(0);


    but i think it's expensive solution

Log in to reply

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