QT-error: LNK1169: 找到一个或多个多重定义的符号

初学Qt,写了一个类,

#ifndef TEACHER_H
#define TEACHER_H
#include 
class teacher : public QObject
{   
 Q_OBJECT
public:   
 explicit teacher(QObject *parent = nullptr);
signals:   
void hungry();
public slots:};
#endif // TEACHER_H
#include "teacher.h"
#include 
teacher::teacher(QObject *parent) : QObject(parent)
{
}
inline void teacher::hungry()
{   
 qDebug()<<"I am hungry";
}
在Widge.h中包含了teacher.h的头文件,在widge.cpp中对其进行调用,
this->tea=new teacher(this);

结果显示:error: LNK1169: 找到一个或多个多重定义的符号!

解决方案:将类teacher中的函数设置为内联函数

inline void teacher::hungry() 即可。

记:另一个类student,为槽函数,它的槽函数treat()是slots,不要设置为inline,否则又会提示无法解析的外部符号。

你可能感兴趣的:(编程,qt,开发语言)