Congratulations to our 2022 Qt Champions!

[SOLVED] Undefined reference for « vtable for myGLWidget »

  • Hi,

    first of all, I'm sorry but I don't use QtCreator. At the beginning, my project didn't need Qt so I began on the IDE NetBeans.

    So this is my problem.

    Here is the code : myGLWidget.h

    @#ifndef MYGLWIDGET_H
    #define MYGLWIDGET_H

    #include <QGLWidget>
    #include <QTimer>
    #include <QKeyEvent>

    class myGLWidget : public QGLWidget
    explicit myGLWidget(int framesPerSecond = 0, QWidget *parent = 0, char *name = 0);
    virtual void initializeGL() = 0;
    virtual void resizeGL(int width, int height) = 0;
    virtual void paintGL() = 0;
    virtual void keyPressEvent( QKeyEvent *keyEvent );

    public slots:
    virtual void timeOutSlot();

    QTimer *t_Timer;


    #endif // MYGLWIDGET_H@

    And myGLWidget.cpp :

    @#include "myGLWidget.h"

    myGLWidget::myGLWidget(int framesPerSecond, QWidget *parent, char *name) :
    if(framesPerSecond == 0)
    t_Timer = NULL;
    int seconde = 1000; // 1 seconde = 1000 ms
    int timerInterval = seconde / framesPerSecond;
    t_Timer = new QTimer(this);
    connect(t_Timer, SIGNAL(timeout()), this, SLOT(timeOutSlot()));
    t_Timer->start( timerInterval );

    void myGLWidget::timeOutSlot()

    On the properties, I have :

    C++ Compiler :
    Include Directories :

    And in the linker :


    I also have an run-time directory for the librairies :

    That's it. And I use QT 5.4.

    So the problem is when I run the project. Here is the error :

    @"/usr/bin/make" -f nbproject/ QMAKE= SUBPROJECTS= .build-conf
    make[1]: entrant dans le répertoire « /home/sim/NetBeansProjects/KinectProjectMa1 »
    "/usr/bin/make" -f nbproject/ dist/Debug/GNU-Linux-x86/kinectprojectma1
    make[2]: entrant dans le répertoire « /home/sim/NetBeansProjects/KinectProjectMa1 »
    mkdir -p dist/Debug/GNU-Linux-x86
    g++ -fPIC -o dist/Debug/GNU-Linux-x86/kinectprojectma1 build/Debug/GNU-Linux-x86/_ext/1729875118/moc_discovery.o build/Debug/GNU-Linux-x86/_ext/1729875118/moc_huebridgeconnection.o build/Debug/GNU-Linux-x86/_ext/1729875118/moc_light.o build/Debug/GNU-Linux-x86/_ext/1729875118/moc_lightinterface.o build/Debug/GNU-Linux-x86/_ext/1729875118/moc_lights.o build/Debug/GNU-Linux-x86/Device.o build/Debug/GNU-Linux-x86/KinectDisplay.o build/Debug/GNU-Linux-x86/LedDevice.o build/Debug/GNU-Linux-x86/ListDevice.o build/Debug/GNU-Linux-x86/RgbDevice.o build/Debug/GNU-Linux-x86/SoundDevice.o build/Debug/GNU-Linux-x86/discovery.o build/Debug/GNU-Linux-x86/huebridgeconnection.o build/Debug/GNU-Linux-x86/light.o build/Debug/GNU-Linux-x86/lights.o build/Debug/GNU-Linux-x86/main.o build/Debug/GNU-Linux-x86/myGLWidget.o -L/usr/local/lib -L/usr/lib/x86_64-linux-gnu -L../../Qt/5.4/gcc_64/lib -Wl,-rpath,../../Qt/5.4/gcc_64/lib -lGLU -lglut -lopenal -lOpenNI -lGL -lalut -lQt5Core -lQt5Gui -lQt5OpenGL -lQt5OpenGLExtensions -lQt5Network -lQt5Qml -lQt5Quick -lQt5Widgets -lQtCore -lQtGui -lQtNetwork -lQtOpenGL
    build/Debug/GNU-Linux-x86/myGLWidget.o: dans la fonction « myGLWidget::myGLWidget(int, QWidget*, char*) »:
    /home/sim/NetBeansProjects/KinectProjectMa1/myGLWidget.cpp:11: référence indéfinie vers « vtable for myGLWidget »
    /home/sim/NetBeansProjects/KinectProjectMa1/myGLWidget.cpp:11: référence indéfinie vers « vtable for myGLWidget »
    collect2: error: ld returned 1 exit status
    make[2]: *** [dist/Debug/GNU-Linux-x86/kinectprojectma1] Erreur 1
    make[2]: quittant le répertoire « /home/sim/NetBeansProjects/KinectProjectMa1 »
    make[1]: *** [.build-conf] Erreur 2
    make[1]: quittant le répertoire « /home/sim/NetBeansProjects/KinectProjectMa1 »
    make: *** [.build-impl] Erreur 2@

    As you guess, I don't know why I have this error. If you could help me !

    Thank you

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    You likely added the Q_OBJECT macro after first building your software. Re-run qmake and build again. You whould then be good to go

  • Thank you for your quick response.
    I guess I juste have to run qmake on my project's directory ? (with no option ?)
    I just tried but after that, I got a new weird error.

    In another file on my project I have :

    @#include <XnCppWrapper.h>@

    situated here : ./usr/include/ni/XnCppWrapper.h

    And in my include directories I have : ./usr/include/ni

    And when I run the project I got :

    @g++ -c -m64 -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++-64 -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. -I. -o Device.o Device.cpp
    In file included from Device.cpp:8:0:
    Device.h:11:26: fatal error: XnCppWrapper.h: Aucun fichier ou dossier de ce type
    compilation terminated.

    I guess I made a mistake with qmake ?

  • Lifetime Qt Champion

    Do you have that path in your pro file ?

    Something like:
    INCLUDEPATH += /usr/include/ni

  • I added it.
    To make it easier, I create a new project on QtCreator.
    I added all the librairies (I think) by right clicking on the project, add librairies, extern librairies ...
    So the last error are correct now. I have a last one and a 'warning'.

    Now this line
    @virtual void keyPressEvent( QKeyEvent keyEvent );@
    in my file above give me an error :
    @/home/sim/build-ProjectMA1-Desktop_Qt_5_4_0_GCC_64bit-Debug/moc_myglwidget.o:-1: erreur : undefined reference to `myGLWidget::keyPressEvent(QKeyEvent

    And the warning is :
    @The /home/sim/build-ProjectMA1-Desktop_Qt_5_4_0_GCC_64bit-Debug/moc_huebridgeconnection.cpp file was deleted outside of Qt Creator. Do you want to save it under a different name or close the editor?@

    but I didn't touch anything ...

    Thank for your help

  • Lifetime Qt Champion

    You didn't implement keyPressEvent

    moc files are regenerated when you modify your class so if you happen to have it opened in Qt Creator you will have this warning

  • Everything works, thank you very much !

Log in to reply