我编写了一段代码,主要是想实现点击按钮后消隐第一个窗口显示第二个窗口的功能,编译也能通过,但是运行后点击按钮没有反应,提示错误为
QObject::connect: No such slot QDialog::ss()
QObject::connect: (sender name: 'unnamed')
QObject::connect: (receiver name: 'page')
源代码如下:
/* project.h */
#include<qwidget.h>
#include<qdialog.h>
#include<qpushbutton.h>
class MyMainWindow: public QWidget
{
Q_OBJECT
public:
MyMainWindow();
QDialog *dialog;
QDialog *dialog1;
QPushButton *button;
QPushButton *button1;
public slots:
void ss();
};
/* main.cpp */
#include<qapplication.h>
#include"project.h"
void MyMainWindow::ss()
{
dialog->hide();
dialog1->show();
}
MyMainWindow::MyMainWindow()
{
setGeometry(0,0,800,600);
QDialog *dialog = new QDialog(0,"page",FALSE);
dialog->setCaption("dialog");
dialog->setGeometry(0,0,800,600);
QPushButton *button = new QPushButton("huan ying",dialog);
button->setGeometry(50,20,200,80);
QDialog *dialog1 = new QDialog(0,"page1",FALSE);
dialog1->setCaption("dialog1");
dialog1->setGeometry(0,0,800,600);
QPushButton *button1 = new QPushButton("huan ying1",dialog1);
button1->setGeometry(50,20,200,80);
dialog1->show();
connect(button,SIGNAL(clicked()),dialog,SLOT(ss()));
}
int main(int argc,char **argv)
{
QApplication a(argc,argv);
MyMainWindow w;
a.setMainWidget(&w);
//w.show();
return (a.exec());
}
我是qt初学者,仿照kde 2/qt 4.1编写的程序,麻烦各位大侠予以指点