刚接触qt,按书上写的编了一个简单的槽(myquitslot())的程序
编译通过了
但是不知道为什么,运行的时候出现找不到槽myquitslot的错误提示
label.h代码:
#include<qwidget.h>
#include<qpushbutton.h>
class mywindows : public QWidget
{ Q_OBJECT
public:
mywindows();
public slots:
void myquitslot();
private:
QPushButton *b1;
};
下面是label.cpp
#include<qfont.h>
#include<qapplication.h>
#include<stdlib.h>
#include"label.h"
mywindows::mywindows()
{
setGeometry(100,100,200,170);
b1=new QPushButton("button1",this);
b1->setGeometry(20,20,100,80);
b1->setFont(QFont("times",18,QFont::Bold));
connect(b1,SIGNAL(clicked()),qApp,SLOT(myquitslot()));
}
void mywindows::myquitslot()
{
exit(0);
}
接下来是main.cpp
#include<qapplication.h>
#include"label.h"
int main(int argc,char **argv)
{
QApplication a(argc,argv);
mywindows w;
a.setMainWidget(&w);
w.show();
a.exec();
}
我的版本是3。0,编译命令 使用的 是 qmake -project;qmake;make
哪位热心的朋友帮我看看哪出了错,
错误信息是no such slot myquitslot::QApplication