Results 1 to 4 of 4

Thread: "undefined reference for vtable" problem

  1. #1
    Join Date
    Mar 2011
    Posts
    21
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Unhappy "undefined reference for vtable" problem

    Hi.

    I've downloaded a simple application to see how I can draw using Opengl.

    The project has only the main.cpp that have the following code:
    Qt Code:
    1. #include <QtGui/QApplication>
    2. #include <QGLWidget>
    3. #include <QHBoxLayout>
    4. #include <QSize>
    5. #include <QPushButton>
    6.  
    7. class MyGLWidget : public QGLWidget
    8. {
    9. Q_OBJECT
    10. public:
    11. MyGLWidget (QWidget* parent ) : QGLWidget(parent)
    12. {
    13. }
    14. float red, blue, green;
    15. void initializeGL()
    16. {
    17. red = 0;
    18. blue = 0;
    19. green = 0;
    20. }
    21.  
    22. public slots:
    23.  
    24. void resetColor()
    25. {
    26. red = 0;
    27. blue = 0;
    28. green = 0;
    29. update();
    30. }
    31.  
    32. void paintGL()
    33. {
    34. red += 0.007;
    35. blue += 0.002;
    36. green += 0.005;
    37. glClearColor(red,green,blue,0);
    38. glClear(GL_COLOR_BUFFER_BIT);
    39. }
    40. };
    41.  
    42.  
    43. class MiaMainWindow:public QWidget
    44. {
    45. public:
    46. MiaMainWindow ():QWidget(NULL){
    47. MyGLWidget *glWidget = new MyGLWidget(this);
    48. QHBoxLayout *layout = new QHBoxLayout(this);
    49. QPushButton *button = new QPushButton("Get to the Choppa!!!", this);
    50. setLayout(layout);
    51. layout->addWidget(glWidget);
    52. layout->addWidget(button);
    53. connect(button, SIGNAL(clicked()),glWidget, SLOT(resetColor()));
    54. setWindowTitle("Hello World!");
    55. sizeHint();
    56. }
    57.  
    58. QSize sizeHint() const
    59. {
    60. return QSize(100,100);
    61. }
    62.  
    63. };
    64.  
    65. int main(int argc, char** argv){
    66.  
    67. QApplication app(argc, argv);
    68. MiaMainWindow win;
    69. win.show();
    70. int res = app.exec();
    71. return res;
    72. }
    To copy to clipboard, switch view to plain text mode 

    and the .pro is the following one:

    Qt Code:
    1. #-------------------------------------------------
    2. #
    3. # Project created by QtCreator 2011-09-14T20:01:51
    4. #
    5. #-------------------------------------------------
    6.  
    7. QT += core
    8. QT += gui
    9. QT += opengl
    10.  
    11. TARGET = tryme
    12. CONFIG += console
    13. CONFIG -= app_bundle
    14. TEMPLATE = app
    15. SOURCES += main.cpp
    To copy to clipboard, switch view to plain text mode 

    But, when I compile it (using qtcreator 2.3.0 with Qt 4.7.4 and MinGW 4.4), I've the following errror:

    debug/main.o: In function `MyGLWidget':
    dir\tryme-build-desktop-Qt_4_7_3_for_Desktop_-_MinGW_4_4__Qt_SDK__Debug/../tryme/main.cpp:12: undefined reference to `vtable for MyGLWidget'
    dir\tryme-build-desktop-Qt_4_7_3_for_Desktop_-_MinGW_4_4__Qt_SDK__Debug/../tryme/main.cpp:12: undefined reference to `vtable for MyGLWidget'
    collect2: ld returned 1 exit status
    mingw32-make[1]: *** [debug\tryme.exe] Error 1
    mingw32-make: *** [debug] Error 2
    The process "C:\QtSDK\mingw\bin\mingw32-make.exe" exited with code 2.
    Error while building project tryme (target: Desktop)
    When executing build step 'Make'
    I've read something about this error but I don't know where's the error. Can anyone help me, please?

    Thanks in advance for your replies.

    Regards.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,014 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: "undefined reference for vtable" problem

    qmake only looks for Q_OBJECT macro in header files. So either move your class definition to a header file (and add it to your project and rerun qmake) or force running moc on your main.cpp by writing #include "main.moc" under the class definition (and rerun qmake).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    May 2011
    Posts
    9
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: "undefined reference for vtable" problem

    That's strange, but try to remove the Q_OBJECT macro from the class definition.

  4. #4
    Join Date
    Mar 2011
    Posts
    21
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: "undefined reference for vtable" problem

    Really thanks. It solved my problem :-)

Similar Threads

  1. Replies: 2
    Last Post: 27th August 2011, 12:59
  2. Replies: 11
    Last Post: 20th March 2011, 08:38
  3. undefined reference to 'vtable ...'
    By GUIman in forum Newbie
    Replies: 5
    Last Post: 10th March 2011, 01:38
  4. "Undefined reference to" error
    By f.tristano in forum Qt Programming
    Replies: 4
    Last Post: 2nd February 2009, 10:00
  5. Undefined reference to 'vtable for XXX'
    By Sheng in forum Qt Programming
    Replies: 4
    Last Post: 17th October 2008, 15:59

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.