signals in a derived class ?
-
I have a base class which has signals:
class MsgDecoder : public QObject { Q_OBJECT private: QString mstrMsgType; eDestination meDest; static tMsgTypesMap msmpMsgTypes; public: MsgDecoder(const QString& crstrMsgType, const eDestination ceDest); virtual bool blnDecode(const QJsonObject& crobjMsg) = 0; QString cstrMsgType() const { return mstrMsgType; } static bool blnDecodeMsgByType(const QString& crstrMsgType, const QJsonObject& crobjMsg); eDestination eDest() { return meDest; } static eDestination getDestFromMsg(const QJsonObject& crobjMsg); static eDestination getDestFromMsg(const QString& crstrMsg); static eDestination getDestFromMsgType(const char* cpszMsgType); signals: void error(const QString& crstrErrorMsg); };
I have several working derived classes based on the above, today I've added a new class:
class SessionMsgRestarted : public MsgDecoder { public: SessionMsgRestarted(); virtual bool blnDecode(const QJsonObject &crobjMsg); signals: void traineeRestarted(const QString& crstrMACaddress); };
However I'm getting very strange compilation errors which I cannot see what the cause is:
sessionmsg.obj:-1: error: LNK2019: unresolved external symbol "public: void __thiscall SessionMsgRestarted::traineeRestarted(class QString const &)" (?traineeRestarted@SessionMsgRestarted@@QAEXABVQString@@@Z) referenced in function "public: virtual bool __thiscall SessionMsgRestarted::blnDecode(class QJsonObject const &)" (?blnDecode@SessionMsgRestarted@@UAE_NABVQJsonObject@@@Z) debug\trngServer.exe:-1: error: LNK1120: 1 unresolved externals
I'm just wondering is there any restriction or limitation on signals in derived classes?
-
@SPlatten
Yourclass SessionMsgRestarted
does not specifyQ_OBJECT
. Even though derived from a class which does, I believe you must specify this to declare a signal in any class? And then don't forget to do a change-underpants rebuild when you add that macro to an existing previously-compiled class :) -
@JonB , thank you, I thought you had the solution, but now I get:
sessionmsg.obj:-1: error: LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __thiscall SessionMsgRestarted::metaObject(void)const " (?metaObject@SessionMsgRestarted@@UBEPBUQMetaObject@@XZ) sessionmsg.obj:-1: error: LNK2001: unresolved external symbol "public: virtual void * __thiscall SessionMsgRestarted::qt_metacast(char const *)" (?qt_metacast@SessionMsgRestarted@@UAEPAXPBD@Z) sessionmsg.obj:-1: error: LNK2001: unresolved external symbol "public: virtual int __thiscall SessionMsgRestarted::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@SessionMsgRestarted@@UAEHW4Call@QMetaObject@@HPAPAX@Z) sessionmsg.obj:-1: error: LNK2019: unresolved external symbol "public: void __thiscall SessionMsgRestarted::traineeRestarted(class QString const &)" (?traineeRestarted@SessionMsgRestarted@@QAEXABVQString@@@Z) referenced in function "public: virtual bool __thiscall SessionMsgRestarted::blnDecode(class QJsonObject const &)" (?blnDecode@SessionMsgRestarted@@UAE_NABVQJsonObject@@@Z) debug\trngServer.exe:-1: error: LNK1120: 4 unresolved externals
-
@SPlatten
Basically, if you add (or presumably also remove)Q_OBJECT
to a class which you previously compiled without it, you need to force a full rebuild every time. I do it via deleting all the files as I thought some peeps say rebuild alone is not enough, but I don't know. And any time I get a Qt link error which I don't expect/impenetrable message and looks vaguely like it might be related to objects/metas etc. I do that before I start wondering if I have made some other mistake :) -
@JonB said in signals in a derived class ?:
Basically, if you add (or presumably also remove) Q_OBJECT to a class which you previously compiled without it, you need to force a full rebuild every time. I do it via deleting all the files as I thought some peeps say rebuild alone is not enough, but I don't know. And any time I get a Qt link error which I don't expect/impenetrable message and looks vaguely like it might be related to objects/metas etc. I do that before I start wondering if I have made some other mistake :)
When changing
Q_OBJECT
and/or signals/slots, you have to rerun the MOC. When you are lucky QtCreator detect those changes and rerun himself the MOC.With qmake based projects, you can rerun qmake which will rerun the MOC and update the makefile and then rebuild the project.
Width cmake projects, I don't know, I have no experience.
At least, if nothing works, deleting the build directory is the solution which always works ;)
-
@JonB said in signals in a derived class ?:
I do that before I start wondering if I have made some other mistake :)
"Clean & (Re-)Build" and "qmake" is like being
root
on Linux or rebooting your Windows machine :-)
Fixes a lot of errors ;-)