View Full Version : Edit Control on a TableView

7th August 2015, 16:06
I have attached a pic to illustrate my problems. I would love to manage some behind the scene activities when the user selects an option on the last row (actually its a new blank row inserted whenever the "Number" field of the previous row is updated with a number. It is inserted by a trigger on my Sqlite db) . The delete Column is the last column..its intended to delete the line when the user clicks on the IndexWidget, however, in some instances, the deletion is carried out on the wrong row I would like help here too.

I have written a function for this as shown below has worked once and never again:

void clsList::addSbj()
if (sbjmodel->isDirty()){
int clInd = sbjmodel->fieldIndex("csNo");
int sbjInd = sbjmodel->fieldIndex("subj");
int clNo = 0;
QSqlQuery qry;
qry.exec("SELECT MAX(csNo)FROM setCls_Sbj");
while (qry.next())clNo = qry.value(0).toInt()+1;
int nwrow = ui->sbjV->currentIndex().row();

if (nwrow == sbjProxy->rowCount()-1)
QString sb(sbjProxy->index(nwrow,sbjInd).data().toString());
if (sb == "<SELECT>")return;
QModelIndex index = sbjProxy->index(nwrow,clInd);

This is not working out! Thank you!


7th August 2015, 21:50
What is "not working out" about it?
What event triggers the addSbj() function?

We cannot see your delete logic. However, you are using a proxy on the model so the row number given by the proxy may not be the same as the row number of the underlying model. If you delete through the underlying model be careful you are using the row number from the right model.