PDA

View Full Version : Model/View -- Sql Insert



kroenecker
24th April 2007, 04:56
Where would the appropriate place be to invoke code for inserting an item into a table? In this case I'm dropping onto a view and want something to show up as a result.

Right now I'm calling insert to act on the container in the model. Then I call setdata and finally I actually call a sql statement to insert into the table. Should the sql insert be called elsewhere? I'm a bit uncertain about what would be "natural" in this case.

wysota
24th April 2007, 11:19
Do you use one of the editable sql models (QSqlTableModel or its subclass)? If so, you should be able to do it directly through the model.

kroenecker
1st May 2007, 03:20
Howdy Wysota. Yeah I could have done that, but I implemented my own listmodel that derives from the abstract list model class. I was just wondering where the best place to put my sql statement would be. Of course it works right now, but in terms of the model/view architecture I'm not sure where the "proper" place would be to place the insert.

Just wondering :)

wysota
3rd May 2007, 16:55
IMO in submit(), setData() or insertRow().