[英]eventFilter error in Qt
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*'
从“ QEvent *”类型到“ QKeyEvent *”类型的无效static_cast
invalid use of incomplete type 'struct QKeyEvent'
无效使用不完整类型'struct QKeyEvent'
forward declaration of 'struct QKeyEvent'
前向声明'struct QKeyEvent'
What I want is : 我想要的是:
label setText("ok") keypress Event 'a' in Form
The error message 错误讯息
invalid use of incomplete type 'struct QKeyEvent'
无效使用不完整类型'struct QKeyEvent'
is a pretty good indicator of the problem. 可以很好地说明问题。 You forgot to
#include
the header file for QKeyEvent
. 您忘记了
#include
QKeyEvent
的头文件。 Add the line 添加行
#include <QKeyEvent>
in the file. 在文件中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.