no submit data with editable QComboBox
-
Hello!
I have got a problem with a editable combobox that is mapped with a QSqlRelationalTableModel.
First is create the model and set the relation:
mModelVoucherPos = new QSqlRelationalTableModel(this, ConnProjectDB::db()); mModelVoucherPos->setTable("VoucherPos"); mModelVoucherPos->setRelation(mModelVoucherPos->fieldIndex("CostCenterKey"), QSqlRelation("vCostCenter","CcKey","text"));
Than I map the data with the QComboBox:
mMapVoucherPos=new QDataWidgetMapper(this); mMapVoucherPos->setModel(mModelVoucherPos); mMapVoucherPos->setSubmitPolicy(QDataWidgetMapper::ManualSubmit); mMapVoucherPos->setItemDelegate(new QSqlRelationalDelegate(mMapVoucherPos)); mMapVoucherPos->addMapping(ui->cbCostCenter,8);
With "mMapVoucherPos->submit();" I submit the data to the QSqlite-Database.
It works very well if the combobox is not editable. If I set the combobox editable and open the dialog, the right data is shown in the combobox, but if I submit the column is empty. If I choose any data in the popup-list of the combobox and submit the data the right data is in the database.
So:
If I only open the dialog and close it (including "submit") the data of the combobox is deleted in the database. If I open the dialog and edit the combobox, the right data is in the database.Has anybody an idea why I loose the data of the editable combobox?
Thank you!
Franz
-
I am not sure,
but I guess editable combobox does not update model until editingFinished signal is emmited for
QLineEdit * QComboBox::lineEdit () -
@Mr.-Kibu said:
QDataWidgetMapper
I do not have experience with QDataWidgetMapper,
and not sure I understand the logic correctly but it seems you may try to map QLineEdit provided by combobox instead of combobox itself. According to what I read in documentation this may be a solution.