Qt SqlTableModel Inserting Row Problem
Qt Single programmer last edited by Qt Single programmer
Hello to everybody
i have a problem with inserting records by "QSqlTableModel" so i use the below scenario to explain my problem.
i have table in database with auto generation primary key(for example student table with id primary key auto generation) and i use "QSqltableModel" in my program. so when i want add single row to model and enter all fields for it, inserting method insert record in database nicely and show it to view correctly too.("selectRow(int row)" method update record correctly).
but when I enter all fields except Id(auto generation primary key) in this case inserting record in database work correctly but it doesn't update view correctly and show empty row. i trace Qt code and notice that Qt use "primaryValues(int row)" method to generate "whereStatement" base user input. (for example in this case it generate "ID IS NULL" wherestatement). since id of records generate by database, selectRow() return nothing and record in view doesn't update so show empty row.
this problem raise because Qt doesn't support returning values in inserting records.
i modify some Qt SourceCode methods like selectRow() and solve it but i want to know is there any way to solve this problem without re-implementing Qt sourceCode?