retrieve the text in a specific cell in a QTableWidget?

c++, qt

Solution

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();
}

Problem

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(""); ```

Original source