c++ - Save data in database after tableView data changed -


i showing data sqlite database in qstandarditemmodel in tableview user can edit it. want save these changes database now, once user presses "save" or tries exit unsaved changes (to give promt, in such case).

what best way this? thinking of running update queries. there way run queries on rows have been modified user?

you can use qsqltablemodel show table contents in qtableview :

qsqltablemodel * model = new qsqltablemodel(this,db); model->seteditstrategy(qsqltablemodel::onmanualsubmit); model->settable( "sometable" ); model->select();  ui->tableview->setmodel( model ); 

for saving or cancelling changes can begin tranaction , commit or rollback @ end. starting transaction :

model->database().transaction(); 

code save button:

if(model->submitall())     model->database().commit(); else     model->database().rollback(); 

code cancel button:

model->revertall(); model->database().rollback(); 

Comments

Popular posts from this blog

.htaccess - htaccess convert request to clean url and add slash at the end of the url -

php - facebook and github login HWIOAuthBundle and FOSUserBundle in Symfony2.1 -

hadoop - Sqoop installation export and import from postgresql -