标题:新手求助,大家来帮我看看错在哪里了
作者:larryzhao
日期:2006-05-19 02:06
内容:
刚刚接触KDE/Qt,正在慢慢学习,以下是我写的一个类:
#include
#include
#include
#include
#include
#include
#include
#include
class threeWidget : public QWidget{
Q_OBJECT
public :
threeWidget(QWidget *parent = 0, const char *name = 0){
QWidget(parent, name);
aButton = new QPushButton("topbutton", this);
aLabel = new QLabel("thelabel", this);
//this.addWidget(aButton);
aButton->setGeometry(15, 15, 90, 20);
aLabel->setGeometry(15, 40, 90, 40);
QObject::connect(aButton, SIGNAL(clicked()), this, SLOT(buttonHandler()));
}
publicslots:
void buttonHandler(){
aButton->setText("aaaaa");
}
private:
QPushButton *aButton;
QLabel *aLabel;
};
问题在于,只要加上"Q_OBJECT",编译就会报错:
************************************
main.o: In function `threeWidget':/home/larry_zb/helloworld/src/main.cpp:52: undefined reference to `vtable for threeWidget'
:/home/larry_zb/helloworld/src/main.cpp:52: undefined reference to `vtable for threeWidget'
main.o: In function `~threeWidget':/home/larry_zb/helloworld/src/main.cpp:48: undefined reference to `vtable for threeWidget'
:/home/larry_zb/helloworld/src/main.cpp:48: undefined reference to `vtable for threeWidget'
************************************
可是书上说要设置slot必须要声明"Q_OBJECT",大家帮我看看是那里错了,谢谢大家
PS: 有没有专门讲Qt Designer的电子书呀 ..
#1 [XChinux 05-19 08:07]
Qt Assistant,KAssistant
这就是帮助。
#2 [bruce1007 05-19 10:33]
你的是这样:
public :
threeWidget(QWidget *parent = 0, const char *name = 0){
QWidget(parent, name);
。。。
试试这样:
public :
threeWidget(QWidget *parent = 0, const char *name = 0) : QWidget(parent, name)
{
...
}
#3 [zn2006 05-19 10:33]
把你的代码分开在main.cpp .h .cpp 里面写试试
#4 [larryzhao 05-22 19:15]
自己顶,高手们来帮帮我呀...谢谢了,我实在不知道错在哪里了...
#5 [shiroki 05-22 19:22]
你在加了Q_OBJECT之后要重新生成makefile,还要make clean;make才行