Build error. Unresolved external symbol

  • This is what is output of the error

    moc_widget.obj:-1: error: LNK2019: unresolved external symbol "private: void __cdecl Widget::setValue(int)" (?setValue@Widget@@AEAAXH@Z) referenced in function "private: static void __cdecl Widget::qt_static_metacall(class QObject *,enum QMetaObject::Call,int,void * *)" (?qt_static_metacall@Widget@@CAXPEAVQObject@@W4Call@QMetaObject@@HPEAPEAX@Z)

    I am trying to implement some custom slots and signals for my gui.

    This is how my header looks like

    namespace Ui { class Widget; }
    class Widget : public QWidget
        Widget(QWidget *parent = nullptr);
    private slots:
        void on_pushButton_clicked();
        void setValue(int value);
        void valueChanged(int newValue);
        Ui::Widget *ui;
        void init_gui();
        int normalize(int iterations, int curriternum);
        int m_value;
    #endif // WIDGET_H

    If i remove setValue from private slot it is building properly but if i include that its not build ing.

    My pro file

    QT       += core gui
    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    #ONFIG += c++11
    # You can make your code fail to compile if it uses deprecated APIs.
    # In order to do so, uncomment the following line.
    #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
    INCLUDEPATH += ..\dependencies\eigen\include\eigen3\Eigen
    LIBS += -lwsock32
    LIBS += -lws2_32
    LIBS +=  -lkernel32 -lkernel32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -luuid -lodbc32 -lodbccp32
    SOURCES += \
        main.cpp \
    HEADERS += \
    FORMS += \
    # Default rules for deployment.
    qnx: target.path = /tmp/$${TARGET}/bin
    else: unix:!android: target.path = /opt/$${TARGET}/bin
    !isEmpty(target.path): INSTALLS += target

    As per some posts in stack and qt forum few suggested to run qmake and i did that. When building the error still remains?

  • @aravmadd
    You have declared a private slot setValue() but do not seem to have actually defined the method, hence the link error?

Log in to reply