Getting an item from an empty table widget
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:
Code:
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.
Re: Getting an item from an empty table widget
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.
Code:
item1 = ui.mywidget_table->item(0,1);
if(item1!=0)
{
helper = item1->text();
}
or check that the item exist before calling the item function.
Code:
if( ui.mywidget_table->rowCount() > 0 && ui.mywidget_table->columnCount() > 1)
{
item1 = ui.mywidget_table->item(0,1);
helper = item1->text();
}
Re: Getting an item from an empty table widget
Thanks for your help, gsmiko.
I´m going to test it.
Bye Bye.