PDA

View Full Version : Yet another QSqRelationalTableModel QDataWidgetMapper QComboBox problem



davidovv
3rd February 2014, 02:00
I am struggling for few days now at what seems to be already answered, but i cant find answer for my situation
I am trying to create CRUD form
I have QSqlRelationalTableModel connected to QTableView


m_table->setTable(m_tableName);
m_table->setJoinMode(QSqlRelationalTableModel::LeftJoin);
m_table->select();
ui->table->setModel(m_table);

the same model is connected to QDataWidgetMapper, and mapper is connected to qtableview selection model


mapper = new QDataWidgetMapper(this);
mapper->setItemDelegate(new QSqlRelationalDelegate);
mapper->setSubmitPolicy(QDataWidgetMapper::ManualSubmit);

I create edit form with comboboxes dynamiclly for each field if there is relation


if(m_table->relationModel(fieldIndex)){
QComboBox *cb = new QComboBox();
cb->setModel(m_table->relationModel(fieldIndex));
cb->setModelColumn(m_table->relationModel(fieldIndex)->fieldIndex("name"));
mapper->addMapping(cb, fieldIndex);
}

Whenn i try to edit record with
mapper->submit()
it returnes false, like there is error, but m_table->lastError() is empty, and data is submitted to database!?!?
The strangest thing is that after submit, the table (qtableview) shows key value instead of text value from relational table for submitted row, until i re-select model
What am i doing wrong?

davidovv
5th February 2014, 22:49
anyone has idea why would mapper->submit() return false,
and lastError() is empty
but the data is submited todatabase?

QSqlRelationalTableModel has editStrategy OnFieldChange
mapper submits onManualSubmit