Important: Please read the Qt Code of Conduct -

[SOLVED]Unresolved External Error - Why???

  • Hi Folks!

    I have the following code for a Widget:

    #ifndef GLWIDGET_H
    #define GLWIDGET_H
    #include "globaldef.h"
    #include "ccamera.h"

    class GLWidget : public QGLWidget
    GLWidget(QWidget *parent);
    void initializeGL();
    void resizeGL(int w, int h);
    void paintGL();
    void timerEvent(QTimerEvent *) { update(); }
    void mousePressEvent(QMouseEvent *) { killTimer(timerId); }
    void mouseReleaseEvent(QMouseEvent *) { timerId = startTimer(20); }

    void Render();

    public slots:

    int timerId;
    CCamera pCam;

    #endif // GLWIDGET_H

    And i create a simple Class(without derive from any class from Qt) and with just a constructor like this:
    #ifndef CCAMERA_H
    #define CCAMERA_H

    class CCamera

    #endif // CCAMERA_H

    Why , when i comple the code i receive the following error?
    glwidget.obj : error LNK2019: unresolved external symbol "public: __cdecl CCamera::CCamera(void)" (??0CCamera@@QEAA@XZ) referenced in function "public: __cdecl GLWidget::GLWidget(class QWidget *)" (??0GLWidget@@QEAA@PEAVQWidget@@@Z)
    debug\INS2.exe : fatal error LNK1120: 1 unresolved externals

    Anyone here can help me?

    Kind Regards

  • Hi!
    Just for instance...i just compile the code removing the constructor of the class(renaming it to other method), than works....

    Why this happen?
    How can we work with constructors in Qt, becouse some classes i will need work have a lot of initializations, like Scene Management templates and etc...,

    It will be hard implement the BSP tree without this becouse i need make copy of my objects every time...

    Kind Regards.

  • Again, i start work with the class , and when i use any member of the Camera class , the error starts can i use this class inside a Widget class???

  • Lifetime Qt Champion


    Please enclose your code in coding tags to make it readable (you can just edit your original post)

    Did you implement the CCamera constructor ?

  • Hi SGaist,

    In fact i discover what´s happening...with your help in other post.
    I just dont realize we need run qMake before Rebuild our changes.
    When this changes was updated by the tool the code run as expected.

    Thanks so much for your help.
    Kind Regards.

  • Lifetime Qt Champion

    You're welcome !

    Re-running qmake is not always needed, it depends on the changes you made.

    Since it's all good now, don't forget to update the thread's title to solved so other forum users may know a solution has been found :)

  • When changing something with Designer or some other issue related to QObjects etc, it is a good idea (when strange unexplainable issues appear) to rebuild with qmake.
    Place [SOLVED] on the first post, it will stop us from reading this post to try to help.

Log in to reply