一、问题描述:
编译工程时报错:error: undefined reference to vtable for ClassName,如图示:
二、问题分析:
造成这种错误的原因很多,甚至在纯C++编程过程中也可能出现。下面根据自己情况,具体问题具体分析。
原因:在原先没有Q_OBJECT关键字的工程中添加了该关键字,但是没有执行qmake,直接编译导致出现该错误。
三、例子:
原先工程的类建立:
class CAppConfig
{
public:
CAppConfig(void);
CAppConfig(const CAppConfig &);
CAppConfig &operator = (const CAppConfig &);
void setDefault(void);
.......
};
后来在该类中加入了Q_OBJECT,如下:
class CAppConfig
{
Q_OBJECT
public:
CAppConfig(void);
CAppConfig(const CAppConfig &);
CAppConfig &operator = (const CAppConfig &);
void setDefault(void);
.......
};
要避免错误,先qmake,再build: