model->setTable("centros_programas");
model
->setRelation
(1,
QSqlRelation("provincias",
"id_provincias",
"nombre"));
model->select();
model
->setHeaderData
(0, Qt
::Horizontal,
QObject::tr("Id"));
model
->setHeaderData
(1, Qt
::Horizontal,
QObject::tr("Provincia"));
model
->setHeaderData
(2, Qt
::Horizontal,
QObject::tr("Centro/Programa"));
model
->setHeaderData
(3, Qt
::Horizontal,
QObject::tr("Tipo"));
ui->comboBoxProvincia->setModel(model->relationModel(1) );
ui->comboBoxProvincia->setModelColumn(model->relationModel(1)->fieldIndex("nombre"));
ui->table->setModel(model);
ui->table->setColumnHidden(0, true);
mapper->setModel(model);
mapper->addMapping(ui->comboBoxProvincia, model->fieldIndex("id_provincias") );
mapper->addMapping(ui->lineEditCentro, model->fieldIndex("nombre") );
mapper->addMapping(ui->lineEditTipo, model->fieldIndex("tipo") );
model = new QSqlRelationalTableModel(this, database);
model->setTable("centros_programas");
model->setRelation(1, QSqlRelation("provincias", "id_provincias", "nombre"));
model->setEditStrategy(QSqlTableModel::OnManualSubmit);
model->select();
model->setHeaderData(0, Qt::Horizontal, QObject::tr("Id"));
model->setHeaderData(1, Qt::Horizontal, QObject::tr("Provincia"));
model->setHeaderData(2, Qt::Horizontal, QObject::tr("Centro/Programa"));
model->setHeaderData(3, Qt::Horizontal, QObject::tr("Tipo"));
ui->comboBoxProvincia->setModel(model->relationModel(1) );
ui->comboBoxProvincia->setModelColumn(model->relationModel(1)->fieldIndex("nombre"));
ui->table->setModel(model);
ui->table->setColumnHidden(0, true);
mapper = new QDataWidgetMapper(this);
mapper->setModel(model);
mapper->addMapping(ui->comboBoxProvincia, model->fieldIndex("id_provincias") );
mapper->addMapping(ui->lineEditCentro, model->fieldIndex("nombre") );
mapper->addMapping(ui->lineEditTipo, model->fieldIndex("tipo") );
mapper->setSubmitPolicy(QDataWidgetMapper::ManualSubmit);
connect(ui->table->selectionModel(), SIGNAL(currentRowChanged(QModelIndex,QModelIndex)), mapper, SLOT(setCurrentModelIndex(QModelIndex)));
To copy to clipboard, switch view to plain text mode
ui->comboBoxProvincia->setModel(model->relationModel(1) );
ui->comboBoxProvincia->setModel(model->relationModel(1) );
To copy to clipboard, switch view to plain text mode
Bookmarks