[Qt-interest] Get mapped value from a QSqlRelationalTableModel

Petric Frank pfrank at gmx.de
Mon May 16 18:28:00 CEST 2011


Hello,

not working - tried that already. You are right when it comes to the method 
.setData - here you have to pass the original value not the mapped one in case 
of a mapped column.

It still returns the mapped value from table "maptable" column "mapvalue" (in 
my case a string).

What i want to get is the value of table "source" column #2 (which is in my 
case a number).

A more detailed example:
-------------------------- cut ----------------------------
  QSqlRelationalTableModel *sourcerel = QSqlRelationalTableModel(this);
  sourcerel->setTable("source");
  sourcerel->setEditStrategy(QSqlTableModel::OnManualSubmit);
  sourcerel->setRelation(2,QSqlRelation ("maptable","mapindex","mapvalue"));
  sourcerel->select();
  QVariant var1 (sourcerel->data (sourcerel->index(0, 2), Qt::EditRole));
  QVariant var2 (sourcerel->data (sourcerel->index(0, 2), Qt::DisplayRole));
-------------------------- cut ----------------------------

Both variables - var1 and var2 - contain the same (mapped) value. var1 should 
contain a number, not a string.

Any more hints ?

regards
   Petric

Am Montag, 16. Mai 2011, 12:04:51 schrieben Sie:
> Hi,
> 	use Qt::EditRole in .data method.
> 
> Regards,
> Miguel Angel.
> 
> El 16/05/11 03:46, Petric Frank escribió:
> > Hello,
> > 
> > i use a QSqlRelationalTableModel instance. It ha a mapped field into an
> > into an other table. I used a QSqlRelation to do that.
> > 
> > This is ok for most cases, but sometimes i want to obtain the mapped
> > value instead of the replaced one.
> > 
> > How to get the original value ?
> > 
> > Little code snippet:
> > 
> > ---------------------- cut ---------------------
> > QSqlRelationalModel relmodel (...);
> > relmodel.setTable ("source");
> > relmodel.setRelation (2, QSqlRelation ("maptable", "mapindex",
> > "mapvalue"); ...
> > QVariant value (relmodel.data (relmodel.index (7, 2));
> > ---------------------- cut ---------------------
> > 
> > 
> > Using the last statement i get the value mapped to the one of table
> > "maptable" taken from column "mapvalue".
> > What want is to get the original value from table "source" column number
> > 2.
> > 
> > Of course i want to keep the mapping, because i need it also.
> > 
> > Any hints ?
> > 
> > regards
> > 
> >    Petric
> > 
> > _______________________________________________
> > Qt-interest mailing list
> > Qt-interest at qt.nokia.com
> > http://lists.qt.nokia.com/mailman/listinfo/qt-interest




More information about the Qt-interest-old mailing list