PDA

View Full Version : Getting an item from an empty table widget



ProTonS
10th July 2009, 19:41
Hi, everybody, its my first time here.

I have a little problem, I am a beginner in qt, but I liking it. Well, to the problem:



QTableWidgetItem *item1;
QString helper;
item1 = ui.mywidget_table->item(0,1);
helper = item1->text();


I´ve received a error in the last line because my cell is empty, but I think that I need to test if the cell is empty, how can I make that?

Thx in advance.

Jorge.

gsmiko
11th July 2009, 17:03
Hi ProTonS!

if there is no item on the location specified, the item function will return 0.
Just test the return value to see if it's a valid item or not.


QTableWidgetItem *item1;
QString helper;
item1 = ui.mywidget_table->item(0,1);
if(item1!=0)
{
helper = item1->text();
}
or check that the item exist before calling the item function.



QString helper;
if( ui.mywidget_table->rowCount() > 0 && ui.mywidget_table->columnCount() > 1)
{
QTableWidgetItem *item1;
item1 = ui.mywidget_table->item(0,1);
helper = item1->text();
}

ProTonS
13th July 2009, 02:24
Thanks for your help, gsmiko.

I´m going to test it.

Bye Bye.