Raccoon29
18th September 2008, 09:04
I everyone,
I'm trying to fill a QTableWidget with some items, but when trying setItem it segmentation faults.
// vLastId is a ID int
// n becomes 2
// query is valid
int n=viewport->db->Count("customer_addresses a,contacts c",
"c.id_customer=a.id_customer AND c.id="+QString::number(vLastId));
QSqlQuery query=viewport->db->Select("a.id,a.ragsoc","customer_addresses a,contacts c",
"c.id_customer=a.id_customer AND c.id="+QString::number(vLastId));
// two columns defined elsewhere
ui.tbwcaddresses->setSortingEnabled(false);
ui.tbwcaddresses->setRowCount(n);
int row=0;
while(query.next())
{
CTableWidgetItem *zid=new CTableWidgetItem(query.value(0).toString());
ui.tbwcaddresses->setItem(row,0,zid); // this row fails and throws exception
CTableWidgetItem *iragsoc=new CTableWidgetItem(query.value(1).toString());
ui.tbwcaddresses->setItem(row,1,iragsoc); // this doesn't fail, and seems the same operation!
...
row++;
}
ui.tbwcaddresses->setSortingEnabled(true);
If I bypass the excepting row, the second setitem works well.
I've done this operation tons of times before, but never this problem... What could it be?
Thank you in advance
I'm trying to fill a QTableWidget with some items, but when trying setItem it segmentation faults.
// vLastId is a ID int
// n becomes 2
// query is valid
int n=viewport->db->Count("customer_addresses a,contacts c",
"c.id_customer=a.id_customer AND c.id="+QString::number(vLastId));
QSqlQuery query=viewport->db->Select("a.id,a.ragsoc","customer_addresses a,contacts c",
"c.id_customer=a.id_customer AND c.id="+QString::number(vLastId));
// two columns defined elsewhere
ui.tbwcaddresses->setSortingEnabled(false);
ui.tbwcaddresses->setRowCount(n);
int row=0;
while(query.next())
{
CTableWidgetItem *zid=new CTableWidgetItem(query.value(0).toString());
ui.tbwcaddresses->setItem(row,0,zid); // this row fails and throws exception
CTableWidgetItem *iragsoc=new CTableWidgetItem(query.value(1).toString());
ui.tbwcaddresses->setItem(row,1,iragsoc); // this doesn't fail, and seems the same operation!
...
row++;
}
ui.tbwcaddresses->setSortingEnabled(true);
If I bypass the excepting row, the second setitem works well.
I've done this operation tons of times before, but never this problem... What could it be?
Thank you in advance