Widget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget)
{
ui->setupUi(this);
installEventFilter(this);
}
bool Widget::eventFilter(QObject *target, QEvent *event)
{
if(target == this)
{
if(event->type() == QEvent::KeyPress)
{
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
if(keyEvent->key()==QT::Key_Space)
{
ui->label->setText("ok");
return true;
}
// 마우스 눌린 상태.
}
}
return QWidget::eventFilter(target, event);
}
Error information:
invalid static_cast from type 'QEvent*' to type 'QKeyEvent*'
invalid use of incomplete type 'struct QKeyEvent'
forward declaration of 'struct QKeyEvent'
What I want is :
label setText("ok") keypress Event 'a' in Form
The error message
invalid use of incomplete type 'struct QKeyEvent'
is a pretty good indicator of the problem. You forgot to #include
the header file for QKeyEvent
. Add the line
#include <QKeyEvent>
in the file.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.