Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

retrieve the text in a specific cell in a QTableWidget?

Tags:

c++

qt

I've been trying to use QT4 with a QTableWidget to store data. I seem to be unable to select a cell and get the text out of it and wanted to see why it won't retrieve it.

ui->QTableWidget->item(ui->QTableWidget->rowCount(),0)->setText("");
like image 439
eyecreate Avatar asked Feb 04 '10 21:02

eyecreate


1 Answers

QTableWidget uses indices which are zero based, so qTableWidget->rowCount() is one past the end of your table.

To iterate over your items and see their text, you could do something like this:

// assuming #include <QtDebug>
for (int i=0; i<tableWidget->rowCount(); ++i)
{
    qDebug() << tableWidget->item(i, 0)->text();
}
like image 130
Kaleb Pederson Avatar answered Oct 02 '22 07:10

Kaleb Pederson