Hi,

I'm starting with Qt and CPP. Here is my problem : I have a QTableWidget with data and I want to add a button in the first cell of every row to delete the row.
I subclassed the QToolButtonclass and wanted to add as a attribute a pointer to the neighbour cell.
The idea was that the user could delete randomly any row and every deleteRowButton would know its row with neighbourCell->row() (the widget inserted a cell using setItem() can't know the current row, am I right?).

Here is my code :
the creation of the row with the creation of the deleteRowButton, located in my mainwindow (airflowcalculator.cpp) :
Qt Code:
  1. tableItem->insertRow(newRow);
  2. tableWidgetEraseItem = new deleteRowButton(*tableWidgetName);
  3. tableItem->setCellWidget(newRow, 0, tableWidgetEraseItem);
  4. tableWidgetName = new QTableWidgetItem("my name");
  5. tableItem->setItem(newRow, 1, tableWidgetName);
To copy to clipboard, switch view to plain text mode 

the slot to remove the row in my mainwindow (airflowcalculator.cpp)
Qt Code:
  1. void airflowCalculator::removeAVComponent(int row)
  2. {
  3. tableItem->removeRow(row);
  4. tableItem->selectRow(tableItem->currentRow());
  5. }
To copy to clipboard, switch view to plain text mode 

The deleteRowButton class (deleterowbutton.cpp)
Qt Code:
  1. #include "deleterowbutton.h"
  2. #include <QIcon>
  3.  
  4. deleteRowButton::deleteRowButton(const QTableWidgetItem & neighbourCellTemp)
  5. {
  6. neighbourCell = neighbourCellTemp;
  7. setIcon(QIcon(":/images/delete.png"));
  8. connect(this, SIGNAL(clicked()),this, SLOT(deleteRowSlot()));
  9. }
  10.  
  11. void deleteRowButton::deleteRowSlot()
  12. {
  13. emit deleteRow(neighbourCell->row());
  14. }
To copy to clipboard, switch view to plain text mode 

Of course, I suspect the argument passing to the deleteRowButton but I'm a little bit lost after having tried with pointers and references

Thanks in advance!