QSqltableModel BeforeUpdate??

  • Hi All,

    I have form with tableview its model is a QSqlTableModel... User inserts a record with insertrows.. After inserting user can leave some fields blank .. When he/she changes the row model inserts the data to database.. I want to prevent inserting wrong or blank data to database beforeupdate how can I do this?


    Please be more examplish when explaning I'm a new bie..

  • That should already be taken care of by the model. See http://doc.qt.io/qt-5/qsqltablemodel.html#setEditStrategy. If you setEditstrategy to OnManualSubmit you can choose when to save the new row to the database.

  • Would enforcing rules in your database using triggers not help you here?

    If you want to enforce your business rules in the model, you could subclass QSqlTableModel and re-implement the submit() method.

    Or, change the model's EditStrategy to OnManualSubmit, create a 'Save' button and check the validity of the data in the button handler before calling the model's submitAll() method.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.