QTableWidget. Emit CellChanged signal

There is a QTableWidget. I need to send a cellChanged signal with a row column and text. How can i do this?


I have already connected a signal with a connector. I need to send a signal.


source to share

2 answers

You should use connect

to catch signal


on cell change:

connect(yourTableWidget, SIGNAL(cellChanged(int, int)), this, SLOT(doSomething(int, int)));


You need to create slot

for example doSomething


public slots:
void doSomething(int row, int column)
    // Get cell text
    QString text = yourTableWidget->item(row,column)->text();

    // Emit 
    emit somethingIsDone(row,column,text);


Create a signal somethingIsDone

(or use an existing signal) that uses ( int,int,QString

) parameters (parameters can be in a different order)

    void somethingIsDone(int row, int column, QString text);




You have to make a slot function and use QObject :: connect to connect to the signal cellChanged


For example:

QTableWidget* widget;
widget = new QTableWidget(this);
connect(widget, SIGNAL(cellChanged(int, int)), otherObject, SLOT(youSlot(int, int));


In your slot, you can get the QTableWidgetItem using the received parameters: row and column number. And here you can emit your own signal containing text as well.

QTableWidgetItem* item = widget->item(row, column);
QString textFromItem = item->data(Qt::UserRole);
emit cellChanged(row, column, textFromItem);


Of course, earlier you must declare your own signal:

   void cellChanged(int row, int col, QString text);


Your signal can be connected to another slot in the same way as cellChanged(int, int)



All Articles