[Solved] error LNK2001: unresolved external symbol
-
wrote on 4 Apr 2014, 13:20 last edited by
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)@
-
wrote on 4 Apr 2014, 13:25 last edited by
This looks like the moc_errorMsg.cpp is not up to date or not used when linking your application.
-
wrote on 4 Apr 2014, 13:34 last edited by
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
-
wrote on 4 Apr 2014, 13:39 last edited by JohanSolo
Did you put the Q_OBJECT macro at the beginning of your class declaration? E.g:
class errorMsg : [...] { Q_OBJECT
-
wrote on 4 Apr 2014, 13:46 last edited by
Yes I did
-
wrote on 4 Apr 2014, 13:49 last edited by
What does you errorMsg class declaration look like?
-
wrote on 4 Apr 2014, 13:57 last edited by
@#ifndef ERRORMSG_H
#define ERRORMSG_Hclass errorMsg : public QObject
{
Q_OBJECTpublic:
errorMsg();
~errorMsg();
void writeErrorMsg(QString msg, int value);};
#endif //ERRORMSG_H@
-
wrote on 4 Apr 2014, 14:13 last edited by JohanSolo
Apart from the
-errorMsg();
which I assume is a typo, this looks almost OK. You seem to be missing the
#include <QtCore/QObject>
directive.
-
wrote on 4 Apr 2014, 14:21 last edited by
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"@ -
wrote on 4 Apr 2014, 14:30 last edited by
[quote author="bern69" date="1396621287"]The "~errorMsg();" is the destructor, but it is not so usefull.
[/quote]
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?
-
wrote on 4 Apr 2014, 14:30 last edited by
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?
-
wrote on 4 Apr 2014, 14:42 last edited by
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?
-
wrote on 4 Apr 2014, 14:54 last edited by
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.
6/13