我想在Qt中创建一个类,并将其放在单独的文件中,然后在主文件中使用该类(背景:次线程更新GUI)。因此我写了ReadDPC.h
文件:
class ReadDPC: public QThread
{
//First edit:
Q_OBJECT
//End of first edit
public:
void run();
signals:
void currentCount(int);
};
在我的ReadDPC.cpp
文件中:
void ReadDPC::run()
{
while(1)
{
usleep(50);
int counts = read_DPC();
emit currentCount(counts);
}
}
read_DPC()
是一个函数,返回一个int
值,并且该函数也位于cpp文件中。
但当我尝试编译时,我遇到了错误undefined reference to ReadDPC::currentCount(int)
。为什么?我该如何解决这个问题呢?
编辑:添加了Q_Object
宏,但是没有解决。