PDA

View Full Version : undefined reference to `vtable for MyWidget'



onder
30th June 2006, 17:49
hi i wrote small hello world program but i am taking error like this :



g++ -Wl,-rpath,/usr/qt/4/lib -o sllot mayn.o -L/usr/qt/4/lib -lQtGui -L/var/tmp/pisi/qt4-4.1.4-5/work/qt-x11-opensource-src-4.1.4/lib -L/usr/X11R6/lib -lpng -lSM -lICE -lXi -lXrender -lXrandr -lXcursor -lXinerama -lfreetype -lfontconfig -lXext -lX11 -lQtCore -lz -lm -ldl -lpthread
mayn.o: In function `MyWidget::MyWidget(QWidget*)':
mayn.cpp:(.text+0x31): undefined reference to `vtable for MyWidget'
mayn.cpp:(.text+0x3d): undefined reference to `vtable for MyWidget'
mayn.o: In function `MyWidget::MyWidget(QWidget*)':
mayn.cpp:(.text+0x1db): undefined reference to `vtable for MyWidget'
mayn.cpp:(.text+0x1e2): undefined reference to `vtable for MyWidget'
mayn.o: In function `MyWidget::~MyWidget()':
mayn.cpp:(.text+0x354): undefined reference to `vtable for MyWidget'
mayn.o:mayn.cpp:(.text+0x35b): more undefined references to `vtable for MyWidget' follow
collect2: ld returned 1 exit status
make: *** [sllot] Hata 1




my code is :


#include <QApplication>
#include <QFont>
#include <QPushButton>
#include <QWidget>
#include <QMessageBox>

class MyWidget : public QWidget
{
Q_OBJECT
public:
QPushButton *btn;
MyWidget(QWidget *parent = 0);

~MyWidget();
{
delete btn;
}

public slots:
void test()
{
QMessageBox::information(this, "mesaj", "merhaba dunya");
}
};

MyWidget::MyWidget(QWidget *parent ): QWidget(parent)
{
setFixedSize(150,100);
btn = new QPushButton("tikla", this);
btn->setGeometry(50,30,50,30);

connect(btn,SIGNAL(clicked()),this,SIGNAL(test())) ;

}
MyWidget::~MyWidget()
{
delete btn;
}

int main(int argc, char *argv[])
{
QApplication app (argc,argv);
MyWidget widget;
widget.show();
return app.exec();
}

i am using qt 4.1.4
whats wrong?
thanks a lot

Onder Arslan

jpn
30th June 2006, 18:06
The constructor does not have an implementation body?
If you decide not to separate your class declaration into a header file, you will have to include the appropriate moc file somewhere in your .cpp file.



#include <QApplication>
#include <QFont>
#include <QPushButton>
#include <QWidget>
#include <QMessageBox>

class MyWidget : public QWidget
{
Q_OBJECT
public:
QPushButton *btn;
MyWidget(QWidget *parent = 0)
{
// supply at least an empty body
}

~MyWidget();
{
delete btn;
}

public slots:
void test()
{
QMessageBox::information(this, "mesaj", "merhaba dunya");
}
};

// you will have to include moc file in case you don't use a separate header which is recommended..
#include "mayn.moc"


And re-run qmake so moc will be run on this file next time.

onder
30th June 2006, 18:42
thanks a lot.
it's working now

Onder