Important: Please read the Qt Code of Conduct -

Undefined symbols for architecture x86_64: "QWidget::KeyPressEvent(QKeyEvent*)"

  • Now I understand from searching for a few hours this means that there virtual function that has not been implemented or a v table value that has been missing, I have been trying for the past 4 hours and no luck just to compile a core profile opengl program, from the 4.8 documentation. This is my first time using the QT Frame work so if someone can help me out that would be great =).

    It appears I have implemented the KeyPressEvent virtual function in RenderMii.cpp but its coming up with another error as you can see in the compile error. I am using QTCreator with Clang and I also tried GCC didn't work as well.

    moc_rendermii.o -F/Developer/QtSDK/Desktop/Qt/4.8.0/gcc/lib -L/Developer/QtSDK/Desktop/Qt/4.8.0/gcc/lib -framework QtOpenGL -framework QtGui -framework QtCore -framework OpenGL -framework AGL
    Undefined symbols for architecture x86_64:
    "QWidget::KeyPressEvent(QKeyEvent*)", referenced from:
    RenderMii::KeyPressEvent(QKeyEvent*) in rendermii.o
    ld: symbol(s) not found for architecture x86_64
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    make: *** [] Error 1
    make: Leaving directory `/Users/MichaelChung/projects/RenderMii'
    15:47:23: The process "/usr/bin/make" exited with code 2.
    Error while building project RenderMii (target: Desktop)
    When executing build step 'Make'

  • Here is some code

    #include <QCoreApplication>
    #include <QGLWidget>
    #include <QGLBuffer>
    #include <QGLShaderProgram>
    #include <QKeyEvent>

    class RenderMii : public QGLWidget

    RenderMii(const QGLFormat & gl_format,QWidget * parent = 0);

    virtual void InitializeGL();
    virtual void ResizeGL(int w, int h);
    virtual void PaintGL();

    virtual void KeyPressEvent(QKeyEvent * e);

    bool PrepareShaderProgram(const QString & vertex_shader_path,
    const QString & fragment_shader_path);
    QGLShaderProgram m_shader;
    QGLBuffer m_vertex_buffer;


    void RenderMii::KeyPressEvent(QKeyEvent * e )
    switch ( e->key() )
    case Qt::Key_Escape:

        QGLWidget::KeyPressEvent( e );


    [[marked up code, Tobias]]

  • It's QGLWidget::keyPressEvent( e ) - with a lowercase k. Then for your own method name too, of course, otherwise it wouldn't be a reimplementation of a virtual method, but a completely new method.

  • Hey thanks for replying I got it working silly me I renamed functions with capitals instead of overriding them correctly I forgot that I was overriding members from the base class, anyways thats all fixed and I just learned that RC doesn't support osx lion correctly and the opengl context isn't created properly when I write the shader it tells me #version 150 glsl is not supported which is true since the context set up is version 1.0 opengl :S

Log in to reply