Important: Please read the Qt Code of Conduct -

Inserting row into QSqlQueryModel trough QDataWidgetMapper

  • Hello,

    I have subclassed a QSqlQueryModel and implemented the setData() and flags() function.
    I also implemented the insertRow() function to insert a blanc row in the database (append).
    After that i created a widget that uses the model and a qdatawidgetmapper. With this combination it is possible to edit EXISTING rows.

    Now the problems start when i want to insert a new row. In this case i must create the new row at the start of the widget so i can set the mapper to it. But if the user happens to CANCEL the dialog then i have a blanc row in my database. That can't be right.

    Now my guess is that a standard tablemodel will first cache the insert and submits the change to the database when "submit" on the datamapper is called.

    What is the best way to deal with this. I must use the qsqlquerymodel beceause my database has a lot of tables that cant be mapped with a standard relationaltablemodel. How should i insert and delete rows and prevent (caching?) having bogus data in the database.

Log in to reply