Important: Please read the Qt Code of Conduct -

Undefined reference to resizeEvent(QResizeEvent*)

  • My application includes a class “Parabola” which is a subclass of QOpenGLWindow, which is a subclass of QObject. The Parabola class includes the Q_OBJECT macro:

    #include <QOpenGLWindow>
    #include <QOpenGLFunctions>
    #include <QOpenGLBuffer>
    #include <QOpenGLVertexArrayObject>
    #include <QMatrix4x4>
    class QOpenGLShaderProgram;
    class ParabolaWindow : public QOpenGLWindow,
                   protected QOpenGLFunctions

    The project compiles, but the linker gives this result:

    g++ -Wl,-O1 -Wl,-rpath,/home/oreilly/Qt/5.14.2/gcc_64/lib -o parabola main.o ParabolaWindow.o qrc_qml.o moc_ParabolaWindow.o   /home/oreilly/Qt/5.14.2/gcc_64/lib/ /home/oreilly/Qt/5.14.2/gcc_64/lib/ /home/oreilly/Qt/5.14.2/gcc_64/lib/ /home/oreilly/Qt/5.14.2/gcc_64/lib/ /home/oreilly/Qt/5.14.2/gcc_64/lib/ /home/oreilly/Qt/5.14.2/gcc_64/lib/ -lGL -lpthread   
    moc_ParabolaWindow.o:([_ZTV14ParabolaWindow]+0xa0): undefined reference to `ParabolaWindow::resizeEvent(QResizeEvent*)'
    collect2: error: ld returned 1 exit status
    Makefile:282: recipe for target 'parabola' failed
    make: *** [parabola] Error 1

    Parent class QOpenGLWindow defines method resizeEvent(QResizeEvent*), which is defined in, and I am linking with that library. I have other projects that subclass QOpenGLWindow, yet they do not have this error when I link. What is causing this error?


  • Lifetime Qt Champion

    @Tom-asso said in Undefined reference to resizeEvent(QResizeEvent*):


    You defined resizeEvent() in your class but did not implement it.

  • Lifetime Qt Champion


    Beside @Christian-Ehrlicher good point, you seem to have made it a slot which is wrong. This method will automatically be called but it is not a slot.

  • @Christian-Ehrlicher and @SGaist - thanks very much for help, and you are both right of course. Super-useful to have your additional eyes on my code!

Log in to reply