Hi community,
I need to move the selected items from 1 QTableWidget table to another QTableWidget table by pressing a button (both tables are in the same window).
The moving part is not the problem, the problem is removing the original rows.

Below my code:

Qt Code:
  1. void MainWindow::on_addReportButton_clicked()
  2. {
  3. // availableItemsTable is the source table
  4. // selectedItemsTable is the destination table
  5.  
  6. QList<QTableWidgetItem*> items = ui->availableItemsTable->selectedItems();
  7.  
  8. if (items.isEmpty())
  9. {
  10. return;
  11. }
  12.  
  13. for (auto &item : items)
  14. {
  15. auto selectedItem = ui->availableItemsTable->takeItem(item->row(), 0);
  16.  
  17. ui->selectedItemsTable->insertRow(ui->selectedItemsTable->rowCount());
  18. ui->selectedItemsTable->setItem(ui->selectedItemsTable->rowCount() - 1, 0, selectedItem);
  19. }
  20.  
  21. for (auto &item : items)
  22. {
  23. // Here I should remove the rows in the source table, but it removes wrong rows
  24. ui->availableItemsTable->removeRow(item->row());
  25. }
  26. }
To copy to clipboard, switch view to plain text mode 

In the loop where I try to remove the rows in the source table, it removes wrong rows.

Any idea on what I am doing wrong?

Thanks in advance,
Franco