标题:我这样连接信号和槽为啥不对那,谢谢
作者:wenrou
日期:2006-08-02 17:15
内容:
picturePage是一个类,addImageButton是它里面的一个对象。
现在在另外一个类中connect,原意是关闭程序,可是不管怎么点都没有反应。
开始我将这个connect放在picturePage类中也没有反应。。
请问这是为啥啊。是不是接收信号的不应该是this?
picturePage picturepage;
connect(picturepage.addImageButton,SIGNAL(clicked()),this,SLOT(close()));
#1 [ediwon 08-02 21:18]
////////////////////////picture.h//////////////////////////
#ifndef HH
#define HH
#include
class picturePage:public QWidget
{
public:
picturePage();
QPushButton *addImageButton;
};
#endif
//////////////////picture.cpp//////////////////////////
#include "picture.h"
picturePage::picturePage()
{
addImageButton = new QPushButton(this);
}
//////////////////////main.cpp//////////////////////////
#include "picture.h"
int main(int argc, char **argv)
{
QApplication app(argc, argv);
picturePage picturepage;
QObject::connect(picturepage.addImageButton,SIGNAL(clicked()),&picturepage,SLOT(close()));
picturepage.show();
return app.exec();
}
#2 [wenrou 08-03 15:39]
我定义得picturePage不是主窗口,只是一个GroupBox,嵌在主窗口中得,等于我现在有:
mainwindow.h
mainwindow.cpp
main.cpp
picturePage.h
picturePage.cpp五个文件
想在picturePage中通过点击他得一个对象addImageButton关闭主窗口,也就是关闭mainwindow中
定义的Ui。怎么点都没有用,在哪里connect都没有反应。。。。
#3 [jy597329 03-05 09:55]
QObject::connect(picturepage.addImageButton,SIGNAL(clicked()),&app,SLOT(close()));