LNK2019未解析的QObject外部符号 [英] LNK2019 unresolved External Symbol for a QObject

查看:54
本文介绍了LNK2019未解析的QObject外部符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用QMake进行构建时出现以下错误:

I'm getting the following errors when building with QMake:

  • LNK2019:未解析的外部符号"public:void __cdecl TimerTodo :: notify(class TodoBaseTask *)"("notify @ TimerTodo @@ QEAAXPEAVTodoBaseTask @@@ Z")在函数私有:无效__cdecl TimerTodo :: timerOver(void)"中引用(?timerOver @ TimerTodo @@ AEAAXXZ)

  • 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:未解析的外部符号"public:void __cdecl TimerTodo :: hasNotified(Class TimerTodo *)"函数"private:void __cdecl TimerTodo :: timerOver(void)"中引用的(?hasNotified @ TimerTodo @@ QEAAXPEAV1 @@ Z)?(?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个未解决的外部

LNK1120: 2 unresolved externals

这是我的标题:

#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

这是我的出处:

#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);
}

如何解决?

推荐答案

这在 Qt文档:

moc工具读取C ++头文件.如果找到一个或多个包含Q_OBJECT宏的类声明,它将生成一个C ++源文件,其中包含这些类的元对象代码.除其他外,信号和插槽机制,运行时类型信息和动态属性系统都需要元对象代码.

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.

(重点是我的)

因此,您需要将此宏放在每个具有自己信号或插槽的类中.

So you need to put this macro in every class that has its own signals or slots.

这篇关于LNK2019未解析的QObject外部符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆