pcheng
27th December 2012, 12:06
Hello all,
I am trying to populate two combo boxes from another relation using the code below:
// Setup the model to use in the mapper
model = new QSqlRelationalTableModel(this);
model->setTable("Orders");
model->setRelation(7, QSqlRelation("customers", "CustomerNumber", "Name"));
model->setRelation(5, QSqlRelation("employee", "EmployeeNumber", "UserName"));
model->select();
Qt::SortOrder order = Qt::AscendingOrder;
model->sort(0, order);
// Setup the mapper for the order widgets
mapper = new QDataWidgetMapper(this);
mapper->setSubmitPolicy(QDataWidgetMapper::AutoSubmit);
mapper->setModel(model);
mapper->setItemDelegate(new QSqlRelationalDelegate(model));
mapper->addMapping(ui->idLineEdit, 0);
mapper->addMapping(ui->fullfilledCheckBox,1);
mapper->addMapping(ui->fullfilledDateEdit, 2);
mapper->addMapping(ui->orderDateEdit, 3);
mapper->addMapping(ui->dueDateEdit, 4);
mapper->addMapping(ui->employeeComboBox, 5, "currentIndex");
mapper->addMapping(ui->dueTimeEdit, 6);
mapper->addMapping(ui->customerComboBox, 7, "currentIndex");
The attribute names and numbers are correct. The orders relation has employee number in column 5 and customer number in column 7. The code runs and shows the order mapped correctly but the combo boxes are empty.
Any idea why this is happening?
Thanks,
Pericles
I am trying to populate two combo boxes from another relation using the code below:
// Setup the model to use in the mapper
model = new QSqlRelationalTableModel(this);
model->setTable("Orders");
model->setRelation(7, QSqlRelation("customers", "CustomerNumber", "Name"));
model->setRelation(5, QSqlRelation("employee", "EmployeeNumber", "UserName"));
model->select();
Qt::SortOrder order = Qt::AscendingOrder;
model->sort(0, order);
// Setup the mapper for the order widgets
mapper = new QDataWidgetMapper(this);
mapper->setSubmitPolicy(QDataWidgetMapper::AutoSubmit);
mapper->setModel(model);
mapper->setItemDelegate(new QSqlRelationalDelegate(model));
mapper->addMapping(ui->idLineEdit, 0);
mapper->addMapping(ui->fullfilledCheckBox,1);
mapper->addMapping(ui->fullfilledDateEdit, 2);
mapper->addMapping(ui->orderDateEdit, 3);
mapper->addMapping(ui->dueDateEdit, 4);
mapper->addMapping(ui->employeeComboBox, 5, "currentIndex");
mapper->addMapping(ui->dueTimeEdit, 6);
mapper->addMapping(ui->customerComboBox, 7, "currentIndex");
The attribute names and numbers are correct. The orders relation has employee number in column 5 and customer number in column 7. The code runs and shows the order mapped correctly but the combo boxes are empty.
Any idea why this is happening?
Thanks,
Pericles