PDA

View Full Version : Item In QTableWidget



Vidhya
25th July 2012, 12:51
how can i check the item in the Qtablewidget having value or not

sonulohani
25th July 2012, 13:57
QVariant QTableWidgetItem::data ( int role ) const [virtual]

Returns the item's data for the given role.

QString QTableWidgetItem::text () const

Returns the item's text.

Vidhya
26th July 2012, 08:30
for (int row=0 ; row < ui->widget->rowCount();row++)
{
qDebug()<<"Ckeck point X "<<row;
QTableWidgetItem *item_test = ui->widget->item(row, 0);
if(!item_test->text().isEmpty())
{
check_count++;
qDebug()<<"Checkpoint y "<<row;
}
c++;
}
qDebug()<<"Check Count"<<check_count;

for first loop(row=0) its working but in the next loop(row=1) it displays Ckeck point X 1;then the program is terminated
pls help me to fix this problem

Santosh Reddy
26th July 2012, 10:09
Having a row in the QTableWidget does not mean that all the columns on the row will have items on them. Items (QTableWidgetItem) have to be explicitly set on the cell(row, column)



for(int row = 0; row < ui->widget->rowCount(); row++)
{
qDebug() << "Ckeck point X " << row;
QTableWidgetItem *item_test = ui->widget->item(row, 0);
if(item_test != 0) //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
{
if(!item_test->text().isEmpty())
{
check_count++;
qDebug() << "Checkpoint y " << row;
}
}
else
{
qDebug() << "Checkpoint z: Item not set " << row; //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
}
c++;
}
qDebug() << "Check Count" << check_count;