我正在尝试将 QGraphicsView 中的所有按键事件转发到当前在现场的小部件。
我的 QGraphicsView 看起来像这样:
Character_controller::Character_controller(Game_state * game_state) : Game_base_controller(game_state) {
this->character = new Character(this->game_state);
this->scene->addWidget(this->character);
connect(this, SIGNAL(keyPress(QKeyEvent *)), this->character, SLOT(update()));
}
然后,我的角色是 QWidget 的子类,它应该接收所有按键事件
Character::Character(Game_state * game_state) : Base_object(game_state) {
}
Character::~Character() {
}
void Character::update() {
cout << "HELLO FROM TIMER CONNECTED ITEM" << endl;
}
出于某种原因,这不起作用。如何将视图中的所有按键事件转发给我的角色?
我得到的错误是这样的:
Object::connect: No such signal game::Character_controller::keyPress(QKeyEvent *) in implementation/game_controllers/character_controller.cpp:21