Thanks for all answers. It seems I need to grab a book and study about memory licking and destructors.
I made some corrections:
void paliwo::advance(int phase)
{
if(warunek){
QList<QGraphicsItem*>Lista;
samolot *temp_1;
Lista = scene()->items(Qt::AscendingOrder);
for(int i = 0;i<Lista.size();++i)
if(Lista.value(i)->zValue() == 4)
temp = Lista.value(i);
temp_1 = dynamic_cast <samolot*>(temp);
if(temp_1){
temp_1->pobierz(true);
warunek = false;
}
}
if (!phase)
return;
else
setPos(mapToParent(0,3));
if (pos().y() > 400)
scene()->removeItem(this);
}
void paliwo::advance(int phase)
{
if(warunek){
QList<QGraphicsItem*>Lista;
QGraphicsItem* temp;
samolot *temp_1;
Lista = scene()->items(Qt::AscendingOrder);
for(int i = 0;i<Lista.size();++i)
if(Lista.value(i)->zValue() == 4)
temp = Lista.value(i);
temp_1 = dynamic_cast <samolot*>(temp);
if(temp_1){
temp_1->pobierz(true);
warunek = false;
}
}
if (!phase)
return;
else
setPos(mapToParent(0,3));
if (pos().y() > 400)
scene()->removeItem(this);
}
To copy to clipboard, switch view to plain text mode
I decided to use removeItem function. Is it propper in this case?
According to DOC removes the item and all its children from the scene.
Removing but not deleting so what's gonna happen with this item after calling this function?
Allocated memory for item will remain occupied? How does scene handle with items deleting?
When durring animation item reaches position on scene which is out of QgraphicsView display range, is it automatically deleted?
stampede wrote:
temp_1 can be NULL, in that case
Yes it can. But only in case of incompatibility - in my code class samolot inherits form QGraphicItem, so I think its ok -at least I guess so...
Once again thanks for all answers
Bookmarks