Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Storing Changes from TableView to Model to SQLITE Database



  • Hello,

    After reading the Qt documentation and playing around with some code I am still a bit confused as to what each part of my code that stores changes to my database actually does. I have the following code:

    @ database->pointsTableModel->database().transaction();
    if(database->pointsTableModel->submitAll())
    {
    database->pointsTableModel->database().commit();
    }@

    I am unsure as to whether all three of these calls are necessary to save the changes to my persistent database. In leyman's terms what exactly does transaction() do? Instead of calling submitAll() can I just go straight to commit()?

    Thanks,



  • You really should not need all of these calls. One of these should be sufficient:
    @QSqlTableModel::submit();
    QSqlTableModel::submitAll()@

    The "QSqlTableModel":http://qt-project.org/doc/qt-5.0/qtsql/qsqltablemodel.html should be already pointing to your database.


Log in to reply