[Qt-interest] Get the row number from a record

jjDaNiMoTh jjdanimoth at gmail.com
Sat Oct 24 19:35:58 CEST 2009


Hello to all,
I'm trying to pass a QSqlRecord from a QSqlRelationalTable to a form.
The form, if the record is empty, displays empty editing widget (
QLineEdit or QComboBox if there is a relation on the column ), else
displays, for every display widget, the "default" value, that comes
from the record.
All ok with QLineEdit, but I have a problem with the ComboBox. Here is the code:

editRecord = ... ; // Contain all the record passed from the table
nColumn = ..; // Contain the number of the column
...
const QSqlRelationalTableModel *tableModel;
tableModel = qobject_cast<const QSqlRelationalTableModel*> (this->model);
Q_ASSERT(tableModel != 0);
QSqlRelation relation = tableModel->relation(nColumn);

if (relation.isValid()) {

  QPointer<QComboBox> combo = new QComboBox(this);
  QSqlTableModel *extTable = tableModel->relationModel(nColumn);
  combo->setModel(extTable);
  combo->setModelColumn(extTable->record().indexOf(relation.displayColumn()));
  combo->insertItem(-1,"");
  // [1] need to set the default item..

  listText.append(combo);
  return combo;

} else {
   ... // code for QLineEdit: Get
editRecord->value(nColumn).toString() and set text on lineedit.
}

At the point [1], I know that:
 - editRecord->value(nColumn) contains the value of relation's displayColumn.

I don't know how get the row number of the editRecord's value, to call
combobox setCurrentIndex().
There is a way?

Many thanks



More information about the Qt-interest-old mailing list