Error At KeyEvent

2.4k Views Asked by At

I am getting error at keyEvent while implementing snapping. The error is as follows :

error: invalid use of incomplete type 'class QKeyEvent'
 switch(event->key())

My code to Key event is as follows :

void Snap::keyPressEvent(QKeyEvent* event)
    {
    switch(event->key())
    {
    case Qt::Key_Left:
    moveBy(-gridSize, 0);
    break;

    case Qt::Key_Right:
    moveBy(gridSize, 0);
    break;

    case Qt::Key_Up:
    moveBy(0, -gridSize);
    break;

    case Qt::Key_Down:
    moveBy(0, gridSize);
    break;

    default:
    QGraphicsItem::keyPressEvent(event);
    }
    }

Please help me out to solve it.

1

There are 1 best solutions below

0
On BEST ANSWER

You should include QKeyEvent class :

#include <QKeyEvent>