0

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 ?)

Thalia
  • 13,637
  • 22
  • 96
  • 190
  • You should delete `event1` by yourself because you own it. If you would posted it via `QCoreApplication::postEvent` then you won't have to delete it. Not clear about `QGestureEvent* event` and `QTapAndHoldGesture *event` because we don't know how you manage them in caller. – Evgeny S. Mar 17 '16 at 23:10
  • I don't call events. – Thalia Mar 18 '16 at 13:31

0 Answers0