PDA

View Full Version : app core dumps!!



Seema Rao
2nd May 2006, 13:01
Hi I have written a small sample, but while its exiting it core dumps. I am using Qt 4.0.1 on Linux. Am I doing anything wrong here? Some body please help, I have attached the source files.

Thanks in advance,
Seem Rao

zlatko
2nd May 2006, 13:11
Problem in your destructor...try first delete list widgets items and then delete list widget..
If it doesnt help try comment delete items.

jacek
2nd May 2006, 13:19
delete layers;
Object that the layers variable points to is owned by the Qt, and Qt will delete it:
void QLayout::addItem ( QLayoutItem * item ) [pure virtual]
Implemented in subclasses to add an item. How it is added is specific to each subclass.
The ownership of item is transferred to the layout, and it's the layout's responsibility to delete it.


delete [] layers_item;
You didn't allocate that array using new[], so you can't delete it.

Seema Rao
2nd May 2006, 13:37
Then Why is that even if I remove the delete statements sample still cores??

jacek
2nd May 2006, 14:39
Because you add each item to the list twice:

...
layers_item[19]= new QListWidgetItem("Bookshops",layers); // <-- here

for (int i=0;i<=NumItems; i++){
layers_item[i]->setCheckState(Qt::Unchecked);
layers->addItem(layers_item[i]); // <-- and here
}
Remove the second line from that for loop and everything should be OK.

Seema Rao
3rd May 2006, 11:59
I have further problems inserting the same QListWidget to a grid Layout.
My sample core dumps before showing the dialog. Can some body please help I have attached the source files. If I comment QListWidgetItem initialization part app does come up. Am I doing anything wrong here ?

Thanks in advance,
Seema

jpn
3rd May 2006, 12:36
The item array has a size of 19 and you are inserting/indexing 20 items.


NumItems = 20 // tour.h (36)
for (int i=0; i < NumItems; i++) // tour.cpp (104)