PDA

View Full Version : QEvent memory management



staser12
24th August 2010, 07:42
I have a question, who is responsible for deletion of QEvent objects? For example, in the code below I create a new QEvent object and pass it further to parent:



void IxGwText::keyPressEvent(QKeyEvent *event)
{
QString text = event->text();

QKeyEvent *newEvent;

if(text != "")
{
text = text.toLower();
newEvent = new QKeyEvent(event->type(), event->key(), event->modifiers(), text);
QGraphicsTextItem::keyPressEvent(newEvent);
}
else
{
QGraphicsTextItem::keyPressEvent(event);
}
}


newEvent is a newly created event. Is there a memory leak? Who handles the event object deletion? Thanx!

tbscope
24th August 2010, 07:56
When you do not use postEvent, yes, there's a memory leak as your event is not deleted.

Create the event on the stack instead.

staser12
24th August 2010, 08:41
Thanx for your answer. I'll try it.