为什么单击按钮时按钮对象没有收到 sigKK() 信号?
当一个信号发出时,所有的qt对象都能接收到这个信号吗?
代码如下:
class PushButton : public QPushButton
{
Q_OBJECT
signals:
void sigKK();
};
PushButton 类继承自 QPushButton,但此处不连接信号和插槽。这是正确的吗?
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(){
resize(400,200);
connect(this,SIGNAL(sigKK()),this,SLOT(showRecv1()));
button = new PushButton();
button->setText("Hello,All");
button->resize(40,15);
connect(button, SIGNAL(clicked()),this,SLOT(buttonCK()));
connect(button, SIGNAL(sigKK()),this,SLOT(showRecv2()));
//**I can connect sigKK signal with showRecv2 slot here ?****
button->show();
}
~MainWindow(){
}
signals:
void sigKK();
public slots:
void showRecv1(){
cout<<"recved 1"<<endl;
resize(100,100);
}
void showRecv2(){
cout<<"recved 2"<<endl;
button->setText(".....");
}
void buttonCK(){
emit sigKK();
cout<<"emited"<<endl;
}
private:
PushButton *button ;
};
#endif