Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
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 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