刚开始学QT....看了一份教程,可能比较老...很多地方与现在的QT版本对不上.
现在看到信号和槽的链接上.代码如下:
#include <qapplication.h>
#include <qwidget.h>
#include <qpushbutton.h>
//#include <stdlib.h>
class MWindow:public QWidget
{
Q_OBJECT
public:
MWindow();
public slots:
void MwExit();
private:
QPushButton *BtnExit;
};
MWindow::MWindow()
{
setGeometry(200,200,100,300); //the point of Mainform When start
BtnExit=new QPushButton("Select All",this);
BtnExit->setGeometry(10,10,80,30);
BtnExit->setFont(QFont("Times",12,QFont::Bold,TRUE));
connect(BtnExit,SIGNAL(clicked()),this,SLOT(MwExit()));
}
void MWindow::MwExit()
{
BtnExit->setGeometry(30,30,60,30);
exit(0);
}
void main(int argc,char **argv)
{
QApplication a(argc,argv);
MWindow w;
w.show();
a.exec();
}
这里编译为什么通不过...提示很多"undefined reference to `vtable for MWindow'"
如果将上边的Q_OBJECT注释掉之后,编译是成功的.但是这时点击按钮没有任何反应.........
错误在哪里呢?!
[ 此贴被XChinux在2006-12-24 10:07重新编辑 ]