howto add new row to QSqlTableModel with QDataWidgetMapper
Phase one was creating the form to edit an existing row using QSqlTableModel/QDataWidgetMapper. I figured that out, and in the process, learned a lot. After digging around a bit, I cannot figure out how to go about adding a whole new row.
As I said in the other post, the final three lines of the constructor are currently:
Code:
_model
->setFilter
(QString("PARISHNER_ID = %1").
arg(parishionerId
));
_model->select();
_mapper->toFirst();
How do I go about getting the model to a row that does not exist as of yet? so a new parishner can be added?
Re: howto add new row to QSqlTableModel with QDataWidgetMapper
QAbstractItemModel::insertRow() or QSqlTableModel::insertRecord() and then reposition the QDataWidgetMapper current index.
Re: howto add new row to QSqlTableModel with QDataWidgetMapper
Chris,
What isn't clicking with me is that I don't have any data to enter yet, so how can I insert something? I don't even have the primary key yet for this new record. If I were to insert an empty record, how do you deal with the user canceling the add?
Re: howto add new row to QSqlTableModel with QDataWidgetMapper
QSqlTableModel::removeRows() to remove the uncommitted row. Exactly when the data is committed to the database depends on the editStrategy(). If you are on manual submits then this will never go near the database. If you are using the database to generate a unique id for a row then you won't have this until after the data is actually written to the database.