I'm writing phone book software(for educational purposes) I have 1 tableView,one QStandardItemModel,4 buttons(add,edit,delete,clear all)
here is a picture:
Capture.JPG

add button works correctly. But Edit button doesn't work correctly,as I want.
I add one person's number with Add button and then when I want to edit contact,I press edit Button but suddenly it crashes.
Capture.JPG

But,when I add new contact directly in tableView without add button, and then press Edit. That works. I can edit contact without any problems.
Capture.JPG
So,problem is when new contact is added via Add button. I can't see what is the problem.
source code of add and edit buttons

Qt Code:
  1. void MainWindow::on_pushButtonAdd_clicked()
  2. {
  3. ChangeDialog dg;
  4. dg.setWindowTitle(tr("Add new contact"));
  5. if(dg.exec() == QDialog::Accepted){
  6. list << dg.GetList();
  7. for(int i = 0; i < 4;i++){
  8. QStandardItem *item = new QStandardItem(QString("%1").arg(list.at(i)));
  9. item->setEditable(false);
  10. model->setItem(rowCount,i,item);
  11. }
  12. }
  13. rowCount++;
  14. }
  15.  
  16. void MainWindow::on_pushButtonEdit_clicked()
  17. {
  18. ChangeDialog dg;
  19. dg.setWindowTitle(tr("Edit contact"));
  20. QStringList Slist;
  21.  
  22.  
  23. for(int i = 0; i < 4; i++){
  24. Slist.append(model->item(rowCount,i)->text());
  25. //QMessageBox::information(this,"title","asd");
  26. }
  27.  
  28. dg.SetList(Slist);
  29. QStringList list2;
  30. if(dg.exec() == QDialog::Accepted){
  31. list2 << dg.GetList();
  32. for(int i = 0; i < 4;i++){
  33. QStandardItem *item2 = new QStandardItem(QString("%1").arg(list2.at(i)));
  34. item2->setEditable(false);
  35. model->setItem(rowCount,i,item2);
  36. }
  37. }
  38. }
To copy to clipboard, switch view to plain text mode