Reputation: 186
I'm getting the following errors when building with QMake:
LNK2019: unresolved external symbol "public: void __cdecl TimerTodo::notify(class TodoBaseTask *)" (?notify@TimerTodo@@QEAAXPEAVTodoBaseTask@@@Z) referenced in function "private: void __cdecl TimerTodo::timerOver(void)" (?timerOver@TimerTodo@@AEAAXXZ)
LNK2019: unresolved external symbol "public: void __cdecl TimerTodo::hasNotified(class TimerTodo *)" (?hasNotified@TimerTodo@@QEAAXPEAV1@@Z) referenced in function "private: void __cdecl TimerTodo::timerOver(void)" (?timerOver@TimerTodo@@AEAAXXZ)
LNK1120: 2 unresolved externals
This is my header:
#ifndef TIMERTODO_H
#define TIMERTODO_H
#include <QTimer>
class TodoBaseTask;
class TimerTodo : public QTimer
{
public:
TimerTodo(TodoBaseTask *timer);
void StartTimer();
private slots:
void timerOver();
signals:
void notify(TodoBaseTask *todo);
void hasNotified(TimerTodo *timer);
private:
TodoBaseTask *m_todo;
};
#endif // TIMERTODO_H
And this is my source:
#include "timertodo.h"
#include "todobasetask.h"
TimerTodo::TimerTodo(TodoBaseTask *todo)
{
m_todo = todo;
connect(this, SIGNAL(timeout()), this, SLOT(timerOver()));
}
void TimerTodo::StartTimer()
{
QDateTime nextNotify = m_todo->getDeadLine().addDays(-1);
this->start(QDateTime::currentDateTime().msecsTo(nextNotify));
}
void TimerTodo::timerOver()
{
emit notify(m_todo);
emit hasNotified(this);
}
How to fix it?
Upvotes: 2
Views: 2963
Reputation: 35891
This is explained in Qt documentation:
The moc tool reads a C++ header file. If it finds one or more class declarations that contain the Q_OBJECT macro, it produces a C++ source file containing the meta-object code for those classes. Among other things, meta-object code is required for the signals and slots mechanism, the run-time type information, and the dynamic property system.
(emphasis mine)
So you need to put this macro in every class that has its own signals or slots.
Upvotes: 4