Reputation: 1091
Is it possible to use the QDataWidgetMapper
to insert into a SQL database?
So far I'm using the mapper for viewing and updating but not for adding new records. Essentially I would need someway to create a QSqlRecord
from the data associated to the QDataWidgetMapper
.
Upvotes: 1
Views: 726
Reputation: 7170
This is just an example, but the idea is using the insertRow
function provided by the model to insert the row that holds the mapper.
If you're using the QDataWidgetMapper::AutoSubmit
policy, your mapper is myMapper
and your model is called myModel
, you could try something like this:
int row = myMapper->currentIndex();
myMapper->submit();
myModel->insertRow(row);
myMapper->setCurrentIndex(row);
This code could be called from a button (i.e. add item or something like that). You can see a full example here.
Upvotes: 1