PDA

View Full Version : QTableWidget: cellChanged returning all cells?



taraj
17th October 2016, 23:54
Hi

I have the following code for a tableWidget. When I change a cell in the table and the cellChanged signal is called I get all cells in the table 'signalled' and I only want the one that was changed. I need to know the row and column that was changed which is why I am using cellChanged().

tableValueChanged outputs every row and column not just the changed one :(

What am I doing wrong?

Thanks in advance!




int row, col;

for(row = 0; row < tableWidget->rowCount(); row++)
{

for(col = 0; col < tableWidget->columnCount(); col++)
{
connect(tableWidget, SIGNAL(cellChanged(int,int)), this, SLOT(tableValueChanged(int, int)));
}
}

void className::tableValueChanged(int row, int col)
{
qDebug("value changed row = %d, col = %d", row, col);
}

anda_skoa
18th October 2016, 07:01
You only need to connect the signal once.

Cheers,
_

taraj
18th October 2016, 07:18
Thanks for the reply, I removed the 2 for loops so connect was only called once but still got the following for 3 rows and 11 columns??

value changed row = 0, col = 1
value changed row = 0, col = 2
value changed row = 0, col = 3
value changed row = 0, col = 4
value changed row = 0, col = 5
value changed row = 0, col = 6
value changed row = 0, col = 8
value changed row = 0, col = 10
value changed row = 0, col = 11
value changed row = 1, col = 1
value changed row = 1, col = 2
value changed row = 1, col = 3
value changed row = 1, col = 4
value changed row = 1, col = 5
value changed row = 1, col = 6
value changed row = 1, col = 8
value changed row = 1, col = 10
value changed row = 1, col = 11
value changed row = 2, col = 1
value changed row = 2, col = 2
value changed row = 2, col = 3
value changed row = 2, col = 4
value changed row = 2, col = 5
value changed row = 2, col = 6
value changed row = 2, col = 8
value changed row = 2, col = 10
value changed row = 2, col = 11

ChrisW67
18th October 2016, 09:15
The first observation is that there are no col == 0 calls, so it isn't every cell in the table.

This is precisely what you might see if you connect the signal and then populate the table. Where is the table populated?

taraj
20th October 2016, 03:41
I understand, works perfectly now thank you!