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->select();
ui->table->setModel(m_table);
m_table->setTable(m_tableName);
m_table->setJoinMode(QSqlRelationalTableModel::LeftJoin);
m_table->select();
ui->table->setModel(m_table);
To copy to clipboard, switch view to plain text mode
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);
To copy to clipboard, switch view to plain text mode
I create edit form with comboboxes dynamiclly for each field if there is relation
if(m_table->relationModel(fieldIndex)){
cb->setModel(m_table->relationModel(fieldIndex));
cb->setModelColumn(m_table->relationModel(fieldIndex)->fieldIndex("name"));
mapper->addMapping(cb, fieldIndex);
}
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);
}
To copy to clipboard, switch view to plain text mode
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?
Bookmarks