Hello all!

I am having some problems with a QPushButton used inside a QTableview. This button needs to remove the row but when I remove one row its changes the index and the button starts to remove the wrong row.

How can I pass the right parameter to void "MainWindow:n_excluir_clicked(int linha)" ?

Thanks a lot.

Code below:
Qt Code:
  1. void MainWindow::adicionarLinha(QStandardItemModel *modelo, QTableView *tabela)
  2. {
  3. spinBoxDelegar = new spinBoxDelegate(this);
  4.  
  5. QPushButton *excluirButton = new QPushButton(*iconeExcluirButton, "", 0);
  6. excluirButton = new QPushButton(*iconeExcluirButton, "", 0);
  7. excluirButton->setStyleSheet("background-color: rgb(255, 255, 255); color: rgb(255, 255, 255); border: 0");
  8. QSignalMapper *mapearSinalBotaoExcluir = new QSignalMapper(this);
  9.  
  10. modelo->insertRow(modelo->rowCount());
  11. modelo->setData(modelo->index(modelo->rowCount()-1,1), 1);
  12. tabela->setItemDelegateForColumn(1, spinBoxDelegar);
  13. tabela->setIndexWidget(modelo->index(modelo->rowCount()-1,2), excluirButton);
  14. tabela->edit(modelo->index(modelo->rowCount()-1,0));
  15.  
  16. mapearSinalBotaoExcluir->setMapping(excluirButton, modelo->rowCount()-1);
  17. connect(excluirButton, SIGNAL(clicked()), mapearSinalBotaoExcluir, SLOT(map()));
  18. connect(mapearSinalBotaoExcluir, SIGNAL(mapped(int)), this, SLOT(on_excluir_clicked(int)));
  19. }
  20.  
  21. void MainWindow::on_excluir_clicked(int linha)
  22. {
  23. this->modelo1->removeRow(linha);
  24. }
To copy to clipboard, switch view to plain text mode 
Captura de Tela 2014-03-01 às 09.55.39.jpg