• 5674阅读
  • 3回复

我这样连接信号和槽为啥不对那,谢谢 [复制链接]

上一主题 下一主题
离线wenrou
 
只看楼主 倒序阅读 楼主  发表于: 2006-08-02
picturePage是一个类,addImageButton是它里面的一个对象。
现在在另外一个类中connect,原意是关闭程序,可是不管怎么点都没有反应。

开始我将这个connect放在picturePage类中也没有反应。。
请问这是为啥啊。是不是接收信号的不应该是this?

picturePage picturepage;
    connect(picturepage.addImageButton,SIGNAL(clicked()),this,SLOT(close()));
[ 此贴被XChinux在2006-08-02 23:03重新编辑 ]
离线ediwon
只看该作者 1楼 发表于: 2006-08-02
////////////////////////picture.h//////////////////////////
#ifndef HH
#define HH

#include <QtGui>

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();
}
BLOG:
http://www.ediwon.com
-------------------------------
离线wenrou
只看该作者 2楼 发表于: 2006-08-03
我定义得picturePage不是主窗口,只是一个GroupBox,嵌在主窗口中得,等于我现在有:
mainwindow.h
mainwindow.cpp
main.cpp
picturePage.h
picturePage.cpp五个文件

想在picturePage中通过点击他得一个对象addImageButton关闭主窗口,也就是关闭mainwindow中
定义的Ui。怎么点都没有用,在哪里connect都没有反应。。。。
离线jy597329

只看该作者 3楼 发表于: 2007-03-05
QObject::connect(picturepage.addImageButton,SIGNAL(clicked()),&app,SLOT(close()));
快速回复
限100 字节
 
上一个 下一个