Results 1 to 3 of 3

Thread: undefined reference to `vtable for MyWidget'

  1. #1
    Join Date
    Jun 2006
    Posts
    11
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default undefined reference to `vtable for MyWidget'

    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 :
    Qt Code:
    1. #include <QApplication>
    2. #include <QFont>
    3. #include <QPushButton>
    4. #include <QWidget>
    5. #include <QMessageBox>
    6.  
    7. class MyWidget : public QWidget
    8. {
    9. Q_OBJECT
    10. public:
    11. MyWidget(QWidget *parent = 0);
    12.  
    13. ~MyWidget();
    14. {
    15. delete btn;
    16. }
    17.  
    18. public slots:
    19. void test()
    20. {
    21. QMessageBox::information(this, "mesaj", "merhaba dunya");
    22. }
    23. };
    24.  
    25. MyWidget::MyWidget(QWidget *parent ): QWidget(parent)
    26. {
    27. setFixedSize(150,100);
    28. btn = new QPushButton("tikla", this);
    29. btn->setGeometry(50,30,50,30);
    30.  
    31. connect(btn,SIGNAL(clicked()),this,SIGNAL(test()));
    32.  
    33. }
    34. MyWidget::~MyWidget()
    35. {
    36. delete btn;
    37. }
    38.  
    39. int main(int argc, char *argv[])
    40. {
    41. QApplication app (argc,argv);
    42. MyWidget widget;
    43. widget.show();
    44. return app.exec();
    45. }
    To copy to clipboard, switch view to plain text mode 

    i am using qt 4.1.4
    whats wrong?
    thanks a lot

    Onder Arslan
    Last edited by jacek; 30th June 2006 at 19:01. Reason: corrected bbcode tags

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: undefined reference to `vtable for MyWidget'

    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.

    Qt Code:
    1. #include <QApplication>
    2. #include <QFont>
    3. #include <QPushButton>
    4. #include <QWidget>
    5. #include <QMessageBox>
    6.  
    7. class MyWidget : public QWidget
    8. {
    9. Q_OBJECT
    10. public:
    11. MyWidget(QWidget *parent = 0)
    12. {
    13. // supply at least an empty body
    14. }
    15.  
    16. ~MyWidget();
    17. {
    18. delete btn;
    19. }
    20.  
    21. public slots:
    22. void test()
    23. {
    24. QMessageBox::information(this, "mesaj", "merhaba dunya");
    25. }
    26. };
    27.  
    28. // you will have to include moc file in case you don't use a separate header which is recommended..
    29. #include "mayn.moc"
    To copy to clipboard, switch view to plain text mode 

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

  3. #3
    Join Date
    Jun 2006
    Posts
    11
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: undefined reference to `vtable for MyWidget'

    thanks a lot.
    it's working now

    Onder

Similar Threads

  1. how to correctly compile threads support?
    By srhlefty in forum Installation and Deployment
    Replies: 9
    Last Post: 25th June 2006, 19:15
  2. Strange error while using Q3Canvas
    By Kapil in forum Newbie
    Replies: 13
    Last Post: 15th June 2006, 19:36
  3. undefined reference to fftw libraries
    By kmyadam in forum General Programming
    Replies: 2
    Last Post: 9th March 2006, 01:01
  4. linking user space and kernel space programs with qmake
    By zielchri in forum Qt Programming
    Replies: 9
    Last Post: 8th March 2006, 23:11
  5. Linker Errors
    By MarkoSan in forum Qt Programming
    Replies: 5
    Last Post: 7th March 2006, 18:30

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.