Who is responsible for managing events ?
For the following code:
bool MyView::gestureEvent(QGestureEvent *event)
{
if (QGesture *hold = event->gesture(Qt::TapAndHoldGesture))
holdTriggered(static_cast<QTapAndHoldGesture *>(hold));
return true;
}
void MyView::holdTriggered(QTapAndHoldGesture *event)
{
QPoint currentTouchPointPos = event->position().toPoint();
QContextMenuEvent *event1 = new QContextMenuEvent(
QContextMenuEvent::Mouse, currentTouchPointPos,
currentTouchPointPos, Qt::NoModifier);
QGraphicsView::contextMenuEvent(event1);
}
I ran it under Valgrind and it told me I have a memory leak.
Which is the leak, event
or event1
?
Should I delete one of them, or both ? Or do I need to accept or ignore them ?
(I tried deleting event1
because it is the one I created, and Valgrind still said I had a memory leak; but event
is really passed from the caller so I should not touch it, I think - and even about event1
I am not sure - will not sending it to QGraphicsView
take care of it ?)