PDA

View Full Version : How to check if QTableWidgetItem exists ?



rawfool
30th June 2013, 22:00
I'm trying to give a network request based on a QTableWidget's cell data. If a QTableWidgetItem isn't set to a particular cell, then if I try to read the cell's text, the application crashes. Even after I check if the cell data isEmpty() or isNull() doesn't solve the issue as the item itself isn't present.
Is there any way tht I can find the existence of a QTableWidgetItem in QTableWidget ?


QString hRef = QTableWidget::item(nRow, nCol)->text(); // crashes here
if( hRef.isEmpty() || hRef.isNull() )
{
return;
}

anda_skoa
30th June 2013, 22:39
Why not just check the return value of item()?

Cheers,
_

ChrisW67
30th June 2013, 23:02
QTableWidget::item() is not static either... It needs to be invoked on an object, which your code snippet is not doing.

rawfool
1st July 2013, 08:03
Yep, I'm using an object only. I tried to show the api I'm using.
This is how I'm doing.

void CResultsTable::getCVEScore()
{
if(rowCount() == nLoadingRow)
{
bVuln_All = true;
emit loadComplete();
return;
}

QString refStr = this->item(nLoadingRow, Reference_Col)->text(); // <<-----

if(refStr.isEmpty() || refStr.isNull())
{
qDebug() << "Cell is empty";
return;
}
QUrl url;
url.setUrl(QString("http://www.somewebsite.com/get?id=")+refStr);
QNetworkReply *reply = cveNAM->get(QNetworkRequest(url));
Q_UNUSED(reply);
}

How do I check the return value of item ? I mean what do I compare it with ? NULL ?

Thank you.

ChrisW67
1st July 2013, 09:38
Read the docs for QTableWidget::item().

anda_skoa
1st July 2013, 09:54
It returns a QTableWidgetItem*, a pointer, so yes, compare to 0



QTableWidgetItem *cellItem = item(nLoadingRow, Reference_Col);
if (cellItem == 0)
return;


Cheers,
_