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

问题描述

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

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

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文档:

(重点是我的)

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

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

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

05-24 23:30