PDA

View Full Version : QTableWidget crashes on setItem



Raccoon29
18th September 2008, 10: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

spirit
18th September 2008, 10:22
did you create a test application for this table and try to insert items?

Raccoon29
18th September 2008, 10:47
did you create a test application for this table and try to insert items?
No I didn't, because I found the fix: there was the usual SLOT called by cellChanged that did controls before it should. Sorry, thank you anyway for your help. It seems like qtcentre air is enhough to solve problems :)

San_Cou
11th September 2013, 22:29
No I didn't, because I found the fix: there was the usual SLOT called by cellChanged that did controls before it should. Sorry, thank you anyway for your help. It seems like qtcentre air is enhough to solve problems :)

Thank you very much!
I spent so many time with this crash.

Raccoon29
23rd September 2013, 21:56
It's always good to discover to have been helpful even after 5 years!
You're welcome ;)

Miaow
18th August 2016, 19:48
Always helpfull now !

Thanks a lot !