QTableWidget crashes on setItem
I everyone,
I'm trying to fill a QTableWidget with some items, but when trying setItem it segmentation faults.
Code:
// 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
Re: QTableWidget crashes on setItem
did you create a test application for this table and try to insert items?
Re: QTableWidget crashes on setItem
Quote:
Originally Posted by
spirit
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 :)
Re: QTableWidget crashes on setItem
Quote:
Originally Posted by
Raccoon29
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.
Re: QTableWidget crashes on setItem
It's always good to discover to have been helpful even after 5 years!
You're welcome ;)
Re: QTableWidget crashes on setItem
Always helpfull now !
Thanks a lot !