我是新手,我试图从头文件中发出信号并将其捕获到我的主类中。为此已经写了这个头文件:-
KeyBoard.h:-
#ifndef KEYBOARD_H
#define KEYBOARD_H
#include <QObject>
#include <QDebug>
class KeyBoard : public QObject{
Q_OBJECT
public:
KeyBoard();
int keyboard_update(QByteArray recieved_key);
signals:
void keyboard_respoense(QString message);
private:
int level;
int sub_level;
};
#endif
和
KeyBoard.cpp:-
#include "KeyBoard.h"
KeyBoard::KeyBoard()
{
level = 0;
sub_level = 0;
}
int KeyBoard::keyboard_update(QByteArray recieved_key)
{
qDebug() << "recieved key == " << recieved_key;
qDebug() << "button == " << recieved_key.at(8);
emit keyboard_respoense("PRESS ENTER TO SELECT TRAIN");
return 1;
}
在我的主班上,我正在捕捉这样的信号:-
keyboard = new KeyBoard;
connect(keyboard,SIGNAL(keyboard_respoense(QString message)),this,SLOT(send_to_MBU(QString message)));
但是当我使用此行调用keyboard_update函数时:-
keyboard->keyboard_update(raw_data_MBU_qb);
它进入keyboard_update()函数,但从不发出信号,或者可能是发出信号,但我无法捕获它。所以,请告诉我在这里我到底想念什么。
答案 0 :(得分:2)
在connect
函数中,无需提及参数名称。只需声明参数类型即可。像这样连接:-
connect(keyboard,SIGNAL(keyboard_respoense(QString)),this,SLOT(send_to_MBU(QString)));
答案 1 :(得分:0)
要让编译器为您提供帮助,请更新至C ++ 11或更高版本并编写 connect(键盘,&Keyboard :: Keyboard_respoense,this,&SnakeCaseClass:send_to_MBU);