gpt4 book ai didi

c++ - LNK2019 未解析的 QObject 外部符号

转载 作者:行者123 更新时间:2023-11-30 01:52:13 25 4
gpt4 key购买 nike

使用 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

这是我的标题:

#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 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.

(强调我的)

所以你需要把这个宏放在每个有自己的信号或槽的类中。

关于c++ - LNK2019 未解析的 QObject 外部符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24993478/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com