user3443063
user3443063

Reputation: 1623

Qt C++ table fill empty items

I have a simple tableWidget in my GUI that displays 2 columns. In this table I want to fill data which will be saved to a txt-file later. This works well. My problem now is, that if the user doesn`t fill all cells, my program crashes.

I can find a cell containing nothing by using

ui->tab_NFF->item(i,0)->text().isEmpty()
   qDebug() << "Item " <<i<<",0 is empty" ;

but when I try to fill that cell with some text it doesnt work. I tried this:

if (ui->tab_NFF->item(i,0)->text().isEmpty())
    ui->tab_NFF->item(i,0)->setText("0");

Does this item exist after all? Is it just empty or does the computer try to fill a value in a non-existing "item" ? If so, how do I create a new item?

Upvotes: 0

Views: 922

Answers (1)

Venom
Venom

Reputation: 1060

If you don't create an item, there isn't one. Just an empty table with a limited number of rows and columns (that you can choose).

You have to create the item using:

QTableWidgetItem *newItem = new QTableWidgetItem();

I invite you to read the documentation about QTableWidget for more details.

Upvotes: 3

Related Questions