Important: Please read the Qt Code of Conduct -

[Solved] error LNK2001: unresolved external symbol

  • Hello,

    I have three errors and I don't know where it comes from and how to solve it. There were not here before. I have shown topics on the internet, but it's very confusing, and the proposals didn't work for me. The errors are

    @errorMsg.obj : error LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __thiscall errorMsg::metaObject(void)const " (?metaObject@errorMsg@@UBEPBUQMetaObject@@XZ)

    errorMsg.obj : error LNK2001: unresolved external symbol "public: virtual void * __thiscall errorMsg::qt_metacast(char const *)" (?qt_metacast@errorMsg@@UAEPAXPBD@Z)

    errorMsg.obj : error LNK2001: unresolved external symbol "public: virtual int __thiscall errorMsg::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@errorMsg@@UAEHW4Call@QMetaObject@@HPAPAX@Z)@

  • This looks like the moc_errorMsg.cpp is not up to date or not used when linking your application.

  • Yeah that's right at the beginning for the moc generation there is

    @errorMsg.h(13): Note: No relevant classes found. No output generated.@

    But I really don't know how to fix it.

    NB: the file is well included in the .pro file

  • Did you put the Q_OBJECT macro at the beginning of your class declaration? E.g:

    class errorMsg : [...]

  • Yes I did

  • What does you errorMsg class declaration look like?

  • @#ifndef ERRORMSG_H
    #define ERRORMSG_H

    class errorMsg : public QObject

    void writeErrorMsg(QString msg, int value);


    #endif //ERRORMSG_H@

  • Apart from the


    which I assume is a typo, this looks almost OK. You seem to be missing the

    #include <QtCore/QObject>


  • The "~errorMsg();" is the destructor, but it is not so usefull.

    I added your include line but it didn't change anything.

    My includes are

    @#include <QString>
    #include <QFile>
    #include <QTextStream>
    #include <iostream>
    #include <QDateTime>
    #include <QLabel>
    #include <QTextEdit>
    #include <QtCore/QObject>
    #include "mainform.h"@

  • [quote author="bern69" date="1396621287"]The "~errorMsg();" is the destructor, but it is not so usefull.
    Obviously, but the "-" should read as a "~"...

    Indeed the include I told you to add is not needed since many widgets are already included.

    I guess you've already tried to rerun qmake and it didn't change a thing.

    Could you provide your (complete) .pro file?

    Edit: is it only me who sees the tilda as an hyphen?

  • Why would you like to build your errorMsg with Q_OBJECT if you don't declare any signals/slots inside it nor use other Qt's meta-object system services?

  • I removed Q_OBJECT from the class and it works now! Thank you very much! I inserted it because I will program some signals and slots later. If I understand, I have to keep it as commentary until the first slot is inserted?

  • Yes. I don't understand why moc doesn't generate an empty .moc file and some warnings in such case, but it's how it works.

Log in to reply